1

I have tried for days to upload a single file to a directory in my web site:I know I can use Filezilla but I want to automate this for some non-tech people. Just click an Icon that runs a batch file. Sounds easy. I have looked for samples I could just insert my parms into but nothing seems to work. (Code below)

FTP OPEN 72.167.xxx.xx
user Sunshine45
password Thunder34
cd /nwire/wp-contect/uploads/2015/01
put /Les/block7.jpg
Bye

I know it must be something obvious but I'm just not seeing it. I want to insert block7.jpg from a directory on my computer into the website directory. The end result will be to auto update an image on a website.

Thanks for any suggestions and/or help.

2
  • I would suggest you try typing out your script line by line in a command prompt to see if you get any errors or hints. Otherwise I'd recommend you try with telnet or psftp (part of the puTTy package). That might help troubleshoot your issue.
    – Kristian
    Jan 28, 2015 at 1:24
  • Between unix-like systems, scp or rsync would be an easily scriptable upload mechanism. Of course this is less helpful if either client or server is windows.
    – killermist
    Jan 28, 2015 at 1:30

2 Answers 2

1

Jesper's answer shows how to do this in a way that most closely matches the way that the question was written.

I propose another solution: don't use ftp. FTP will not offer security over a network. It can also be problematic with certain network designs, particularly if NAT is used or when a firewall is used. These problems probably won't exist now if manual FTP uploads are working fine, but they could start to exist if someone makes changes. For example, problems could exist if you replace a DSL modem with another DSL modem that provides different features.

The preferred solution is to not use FTP. What you can use instead may be limited base don what the web host provides as an option. One great alternatives is SFTP, implemented with PuTTY's PSFTP.EXE. There may be some ambiguity since there are multiple secure variations of FTP, like FTPS. SCP, implemented with PuTTY's PSCP, may be a bit easier to use in some cases, so I suggest starting with that.

To do this, first grab the files from PuTTY-s download site. http://chiark.greenend.org.uk/~sgtatham/putty/download.html offers pscp.exe and the similar psftp.exe file. The the.earth.li/~sgtatham/putty/latest/x86/… (for version 0.63, which is the latest version at the time of this writing) may be simplest for people who prefer being walked through an easy installation process using a GUI, while the putty.zip file also contains putty.exe and pscp.exe and psftp.exe

The first version of your batch file will look something like this:

C:\Program Files\PuTTY\PSCP.exe -l username C:\dir\stuff\to\upload*.* remoteSever:.

Note the period at the end, which specifies the location where files will go. Customize that as needed.

Once you have that working well, you'll want to object that the user needs to type in a password. Yeah, well, that can be resolved to, but that's just a bit more work, but is generally an option by servers that support using PSFTP or PSCP. You'll probably want to use PuTTYGen to create a key. Save the private key in OpenSSH format (not PuTTYGen's preferred *.PPK format). That private key will need to go onto the server. Using PuTTY will probably be an easier tool to make sure that the private key is installed where it needs to be. Once the private key is handled, the batch file can be modified to use:

C:\Program Files\PuTTY\PSCP.exe -l username -i C:\mykeys\mykey.pub C:\dir\stuff\to\upload*.* remoteSever:.

If PSCP is working well, modernize things slightly by trying PSFTP.exe instead. If that works, that is a bit preferable, as OpenSSH authors note that SFTP is a more developed protocol than SCP.

Alternatives are to use protocols other than FTP, SFTP, or SCP, like HTTP(S). HTTP(S) can probably be automated by using WGET with --post-file=filename but you'll need to find out what URL your web host uses to permit HTTP uploads. Actually, cURL is preferable over WGET. It has a more lenient license, and I believe the code is newer and simpler as well.

There may be other implementations available as well. WinSCP supports a command line client called winscp.com (and there is also the winscp.exe which provides the GUI). Windows Script Host can use HTTP by using an object that is built into Microsoft Windows, so there is no need to download an executable file. Again, I refer to Jesper's answer as an answer that you may find works quite well for you, and that uses software that is typically pre-installed with Windows, so no extra software needs to be downloaded. I'm betting that there are many more options available... you've got lots of choices that you can choose from.

0

This is how to do it:

Put these commands in a separate file; let's name it ftpcommands.txt:

OPEN 72.167.xxx.xx
user Sunshine45
password Thunder34
cd /nwire/wp-contect/uploads/2015/01
put /Les/block7.jpg
Bye

Then this command should do the trick (on Windows, at least):

FTP -s ftpcommands.txt

By the way: If you stated the real user name and password here in the open, I would recommend you change it now. The other information you stated could be enough to find the complete IP address.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .