Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to transfer files to an embedded system which has an root account and an empty password. During development, entering the user name, the password and the file transfer command becomes tedious after a while:
If you have ssh installed, you can use scp (secure copy; in any case, you shouldn't use ftp which doesn't encrypt the password). If you use scp you can just define an alias, such as
Of course you will have to give the command "whatever" and also the password. Maybe not what you wanted.
In ncftp you can define macros, which you put in ~/.ncftp/macros, or something like it, where you can put a list of commands that ncftp then issues. This still requires you to start the program, enter the macro name and password, and quit, though...
The following should work, or beable to be adapted to your needs. I modified a script I have used frequently in the past.
#!/bin/bash
ftp -n <host> <<%%
user root
cd <new dir>
prompt
bin
put <filename>
# You can also following (commented line) to use an argument.
#put $1
bye
%%
Note that if you did have a password, you could put this is a file called .netrc (though I would not keep it around too long with the password, but it is great for anonymous ftp where an "email" must be entered). Also, if you are transfering multiple files at once, you can use mput.
Now I also want to have it fully automatic, where do I put the .netrc and what do I put in there? Since I am developing on a private LAN, my root password is <CR>.
Even in a local network or a disconnected machine, I believe it is best to have a root password, if for no other reason than it forces a person "to become" root and thus be more aware of the danger (comes with power) he/she is now in.
That said, a cronjob is certainly the place for automation. The particulars depend somewhat on the particulars of the problem, which you have not stated.
Further, a couple of notes on the script:
1) the -n option to ftp disables the use of .netrc If you want to use .netrc, leave out the "user root" part. You can also (in general, with -n option) make this "user <user> password" in the script.
2) The parts between the "<<%%" and "%%" are ftp commands. Therefore, the script listed above with comment lines between these markers would produce errors. You probably did not include them or you probably would have mentioned the errors, however I thought I would explicitly state this here in case anyone reads the archive.
I will eventually set the root password shortly before the project is ready for deployment. Thanks for mentioning that the -n disables .netrc, that explains things. I might even set a new root password now since I am not entirely sure how to include a <CR> password in .netrc or on the command line with -n.
As for the comment lines, first I got the errors, then I figured that ftp doesn't like #-comments.
I need this ftp transfer at the end of a make process, so cron is not necessary.
Yuray,
Tried your version again, still the same error:
File "./trans", line 5, in ?
ftp.storbinary("STOR cscope", open('cscope','rb').read)
File "/usr/lib/python2.2/ftplib.py", line 423, in storbinary
buf = fp.read(blocksize)
AttributeError: 'builtin_function_or_method' object has no attribute 'read'
And my source file is truncated to 0 bytes!
To include a passward in the script above, where it says "user root", use "user root <passwd>". For use from .netrc, use just like /bin/bash indicates. Note that of course, as for the password token, "man netrc" indicates - if this token is present in the .netrc file for any user other than anonymous, ftp will abort the auto-login process if the.netrc is readable by anyone besides the user. In otherwords, "chmod 600 ~/.netrc".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.