How to connect SFTP(Linux) from Windows DOS


 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions How to connect SFTP(Linux) from Windows DOS
# 1  
Old 11-12-2008
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
# 2  
Old 11-12-2008
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.
This User Gave Thanks to Annihilannic For This Post:
# 3  
Old 11-12-2008
Quote:
Originally Posted by Annihilannic
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
# 4  
Old 11-13-2008
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".
# 5  
Old 11-18-2008
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
# 6  
Old 11-18-2008
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

# 7  
Old 11-18-2008
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Connect direct - SFTP - List of servers that I can connect

Greetings Experts, I am working for a bank client and have a question on connect-direct and SFTP. We are using Linux RedHat servers. We use connect-direct to transfer (NDM) files from one server to another server. At times, we manually transfer the files using SFTP from one server to another... (2 Replies)
Discussion started by: chill3chee
2 Replies

2. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

3. Windows & DOS: Issues & Discussions

Connect to Windows server from Linux

Hi, We are running Linux server and are required to connect to Windows server and fetch the files from windows server. How can i connect to Windows server from Linux? I have to do this with a automated shell script on Linux I appreciate your response. (4 Replies)
Discussion started by: reachmexyz
4 Replies

4. Shell Programming and Scripting

Connect to Windows from Linux using NetCat

Hi Need help to connect from Ubuntu to Windows using NetCat nc I can not get my script to send new-line Her is what I have tried(sleep 2 ; echo user ; sleep 1; echo pass; sleep 2; echo netstat) | nc -t 10.10.10.34 23 gives this outputÿý%ÿûÿûÿý'ÿýÿýÿûWelcome to Microsoft Telnet Service ... (1 Reply)
Discussion started by: Jotne
1 Replies

5. Ubuntu

Steps to connect linux (Ubuntu) machine from windows 7

Hi, Can anyone give me the steps to connect ubuntu from windows7? Thanks (1 Reply)
Discussion started by: diehard
1 Replies

6. Linux

Help!! trying to connect to linux SSH from windows putty client

Hi, i am trying to connect my Putty session on a windows box to a linux SSH, i have generated private and public key pairs using puttygen, i have set the public one to be in an OPENSSH format... and have put this in my authorized_keys file in linux, when i connect i get the following errors: ... (1 Reply)
Discussion started by: Jtyreman
1 Replies

7. Shell Programming and Scripting

Transfer files from linux server to windows using secure ftp (sftp)

HI, I have to transfer files from linux server to windows using secure ftp (sftp) .Kindly help me out. (3 Replies)
Discussion started by: manushi88
3 Replies

8. Shell Programming and Scripting

Connect to Oracle in Windows XP from Linux HOST

Hi everyone, I have oracle 9i installed in Windows XP and i have ubuntu in VM WARE. I would like to know how to connect to Oracle in windows xp from Linux through shel scripting...... (3 Replies)
Discussion started by: Zimbu
3 Replies

9. UNIX for Advanced & Expert Users

How do I connect windows xp to Linux Red hat unix

I just bought a new pc and my unix software is installed on my old computer. I want to take the hard disk outta my old pc and then install it on my new pc so my new pc has 2 hard drives. now, after my pc new has 2 hard drives, one being unix the other being windows xp, i want to be able to... (7 Replies)
Discussion started by: TRUEST
7 Replies
Login or Register to Ask a Question