Link to home
Start Free TrialLog in
Avatar of cjrcomputers
cjrcomputers

asked on

Upload script for psftp

I have an ssh server and I'm looking for a batch file to upload a file to the server using psftp.  It seems to work fine manually when I'm running it in the command prompt, but when I put it in a batch file and run it fails.
Avatar of Rajeshpola
Rajeshpola

Please give some error message or the script u r using ?
Avatar of Bill Prew
Are you using the -b option to specify the command to run?  

Are you using the -batch option as well in the batch file execution?

Are you using the exact same command from the command prompt as from a batch file, or is there something different?  

What error messages do you get?

Have you tried the -v option to get further error messaging?

~bp
Avatar of cjrcomputers

ASKER

This was the command I was attempting to use in a batch file:

psftp.exe open ****address -l crice -pw password put file

When I attempt to run it I get a usage message with a list of options.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It looks like the file is copying over now, but the command prompt window stays open after it copies.
Did it echo the "quit" command?

You might try adding the -batch option on the command line, not sure if that helps or not.  I would expect the quit command to close the window when it is encountered.

~bp
I did put the quit command in, but no it didn't echo the quit command.
Not sure what editor you are using, but there is a chance that there is no CR,LF after the QUIT.  In your editor make sure you hit RETURN at the end of the QUIT line before saving.

If that doesn't work try putting two lines with QUIT at the end of the file just as a possible clue.

The PUT command does echo in the window though, yes?

~bp
I'm just using notepad to create the batch file.  Below is what echos when I run the batch file.

fsftp.exe ssh.cjrcomputers.com -l crice pw ****** -b move.bat
Using username "crice".
Remote working directory is /
local:  IBMTape.x86.zip => remote:/IBMTape.x86.zip
psftp: unknown command "QUIT"
It looks like you have QUIT in uppercase, try using it in lowercase.

Also, if that doesn't work, try using exit instead, lowercase also.

One other thing, I would not call the command file "move.bat".  Rename it to move.ftp or move.txt or something.  BAT files are special and should only be used for true command scripts, and this file isn't, it's a control file for the fsftp program.

Hope this helps.

~bp
Still not exiting command prompt with quit or exit.  I renamed the file move.txt
Actually, I was looking at docs from a slightly older version.  It looks like you don't need / want the quit at the end of the TXT file anymore.  Take a look at the two links below on the -b option, notice the older version wanted the quit, but the newer version just ends when the TXT file end is reached.

http://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter6.html#6.1.5

http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter6.html#psftp-option-b

~bp
Even without the quit or exit it still stays open...
Have you tried bye as the last line?

~bp
That didn't work either.
Can you walk me through your process?  Did you create a BAT file that does the execute of PSFTP.EXE?  If so, how are you executing that BAT file?

~bp
I have created a batch file with the following in it:

psftp.exe ssh.cjrcomputers.com -l crice -pw ************** -b move.txt

I then have the move.txt file with the following in it:

put IBMTape.x86_6204.zip
bye

I have those both saved on my C drive.  When I double click the batch file the command prompt window opens echoing:

C:\>psftp.exe ssh.cjrcomputers.com -l crice -pw ************************* -b move.txt
Using username "crice".
Remote working directory is /
local:IBMTape.x86_6204.zip => remote:/IBMTape.x86_6204.zip

It ends up copying the file to the server but the window never closes after it is done copying.
That's odd.  I just did a test here doing pretting much exactly what you are and the window closed as soon as the transfer ended.

How large is the ZIP file, could it be taking a while to do the transfer?

Do you ever get the C:\> prompt back after psftp runs, or is the local ==> remote the last line in the window?

You might try a test with a very small test file instead of the ZIP file if it is large, to see what that does.

~bp
I zip file is a little over 100kb and I can tell when its done copying because I go and check.  

The local ===> remote is always the last line in the window.
Try a smaller TXT file just for a test.

Also, if you bring up Task Manager is PSFTP still loaded?

~bp
Using smaller text didn't help.  

Yes psftp.exe is still a running process even after the file has been copied over.
Well, I'm running out of ideas, it feels like a bug in the software, or something interesting in your config.

You may want to report this as a bug at the Putty site.  I did find one past bug that seemed somewhat related, but it claims to be fixed.

http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/psftp-hang.html

Only other thought is to try running your BAT file from a CMD prompt, rather than from Explorer, and see if that acts any differently.

~bp
It hangs when I run it from command prompt as well.  
Sorry to hear it still hangs.  Not sure what else to tell you to try.  I think I answered your initial question so the file xfer is happening now.  I really don't know why PSFTP doesn't exit after transferring the file, you might want to create a new question specifically targeted at that problem to try and get more input.

~bp