?
Solved

Upload script for psftp

Posted on 2009-12-31
24
Medium Priority
?
1,951 Views
Last Modified: 2013-12-02
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.
0
Comment
Question by:cjrcomputers
  • 12
  • 11
24 Comments
 
LVL 4

Expert Comment

by:Rajeshpola
ID: 26152478
Please give some error message or the script u r using ?
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26155378
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26163049
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 26163092
I'm going to assume that "****address" is the host name or address you want to connect to.  I'm also going to assume that "file" is actually the name of a file.

The psftp command line doesn't have the option to execute commands like PUT right on it, instead you will need to create a command file, lets call it myscript.ftp.  Place the following into it:

put filequit

Then try the following command line:

psftp.exe ****address -l crice -pw password -b myscript.ftp

~bp
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26163167
It looks like the file is copying over now, but the command prompt window stays open after it copies.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26163194
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26163218
I did put the quit command in, but no it didn't echo the quit command.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26163255
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26163309
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"
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26163403
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26163421
Still not exiting command prompt with quit or exit.  I renamed the file move.txt
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26163489
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26163675
Even without the quit or exit it still stays open...
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26167414
Have you tried bye as the last line?

~bp
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26167596
That didn't work either.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26167720
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26168792
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.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26170824
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26170906
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.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26170981
Try a smaller TXT file just for a test.

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

~bp
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26177434
Using smaller text didn't help.  

Yes psftp.exe is still a running process even after the file has been copied over.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26179848
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
0
 
LVL 1

Author Comment

by:cjrcomputers
ID: 26180039
It hangs when I run it from command prompt as well.  
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 26182490
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know how boring and exhausting it is to transfer huge web projects developed locally to a webserver simply via FTP. The File Transfer Protocol is a really nice solution if you need to transfer small amounts of files, but if you're plannin…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question