The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > Windows & DOS: Issues & Discussions
.
google unix.com



Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need script to connect sftp servers kittusri9 Shell Programming and Scripting 1 05-10-2008 05:13 AM
how to connect sftp server using script kittusri9 Shell Programming and Scripting 1 05-06-2008 07:12 AM
how to connect to windows from unix ? guhas Shell Programming and Scripting 2 12-19-2005 04:37 PM
Connect from Windows Using SSH aldowsary AIX 12 08-07-2005 03:12 PM
How do I connect windows xp to Linux Red hat unix TRUEST UNIX for Advanced & Expert Users 7 11-21-2002 11:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-11-2008
Registered User
 

Join Date: Nov 2008
Posts: 9
How to connect SFTP(Linux) from Windows DOS

I need to write a batch script for file transfer from SFTP to Windows system. SFTP is on Linux system. I kept this code in batch file and executing it.. but not working.. Even i tried from Command prompt like this "open sftp.host.com" but getting error. Can anyone help with the code and tell me how to connect SFTP from command prompt.

Here is my sample code,

open sftp.host.com
<username>
<password>
lcd <test/test/../>
cd /test/test/test/
get test.txt
quit

--
Thanks,
Mohan
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-12-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 996
You need an SFTP-compatible executable on the Windows side. You can try the psftp.exe that comes with PuTTY. You would store the SFTP commands in a file, say sftpcommands.txt, and use psftp.exe -b sftpcommands.txt.
Reply With Quote
  #3 (permalink)  
Old 11-12-2008
Registered User
 

Join Date: Nov 2008
Posts: 9
Quote:
Originally Posted by Annihilannic View Post
You need an SFTP-compatible executable on the Windows side. You can try the psftp.exe that comes with PuTTY. You would store the SFTP commands in a file, say sftpcommands.txt, and use psftp.exe -b sftpcommands.txt.
I installed Putty with psftp.exe, and kept my scripts in sftpcommands.txt.
I went to command prompt and psftp.exe -b sftpcommands.txt, but it is i am getting this error "'pstfp.exe' is not recognized as an internal or external command, operable program or batch file".

If i open but psftp.exe, it is asking for hostname, login and password. Which is working fine. Can you tell me how to execute that above command which you gave.

--
Thanks,
Mohan Tummalapalli
Reply With Quote
  #4 (permalink)  
Old 11-13-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 996
You will either need to add it to your PATH, or specify the full path to the location of the psftp.exe, e.g. "C:\Program Files\PuTTY\psftp.exe" -b "C:\Documents and Settings\Mohan\My Documents\sftpcommands.txt".
Reply With Quote
  #5 (permalink)  
Old 11-18-2008
Registered User
 

Join Date: Nov 2008
Posts: 9
Thanks it works. I can run my scripts using "C:\Program Files\PuTTY\psftp.exe" -b "C:\Documents and Settings\Mohan\My Documents\sftpcommands.txt".

I have another doubt it the same script, I need to rename file which iam getting from SFTP, i am not sure the file name which iam getting so iam using "*" but as example iam sending this "ren Test*.txt Test123.txt"

Can you tell me how to rename with date format something like test123[DDMMYYYY][time].

--
Thanks,
Mohan
Reply With Quote
  #6 (permalink)  
Old 11-18-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 996
Thsi isn't really a Unix related question, is it? :-)

Windows batch/command/cmd.exe scripting is one of the most ridiculous languages I have ever encountered. Anyway, something like this might work for you:

Code:
for /f "tokens=1-3 delims=/ " %d in ('date /t') do ren test*.txt test%d%e%f.txt
Reply With Quote
  #7 (permalink)  
Old 11-18-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 996
I should mention, you have to double the %s if you are putting this in a batch file, i.e.

Code:
for /f "tokens=1-3 delims=/ " %%d in ('date /t') do ren test*.txt test%%d%%e%%f.txt
I'm not sure how you would include the time in the filename as well (I forgot about that part). Maybe it would be best to install Cygwin and get a real scripting environment!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
sftp, sftp windows

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 09:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66