I am having problems with trying to list a directory on my sftp server to a local .txt file.
I need to use commandline. So i have figured out putty is just about the only client that can do this.
So, using putty i started working towards figuring it out. I managed to get as far as to listing the directory i want (In both psftp, and pscp) which are the putty sftp client and the putty secure file up/download client.
Using this script when pscp.exe (For a .bat script):
start /WAIT D:\pscp.exe -sftp -v -batch -pw password -ls [email protected]:/directory/subdirectory/subdirectory
This lists the directory. I tried adding " C:\filelist.txt" to the end of it, but that only created an empty local file, the directories didn't get listed in it.
And using this script when psftp.exe (For .bat script too):
start /WAIT D:\psftp.exe [email protected] -v -be -bc -batch -pw password -b D:\listcommands.scr
Where listcommand.scr is called to initiate more commands in the psftp, it contains:
ls /directory/subdirectory/subdirectory > D:\listdir.txt
But neither will write the directory listing to the local .txt file. The psftp.exe command doesn't even create an empty .txt file like the pscp.exe command does. The listcommands.scr command doesn't work without the ">" either.
Thanks to anyone who has any help to offer in regards to this.
I think the "filelist.txt" file is empty because you are spawning a new command and as a result the output from the psftp
command is being written to a different stdout to the one you are redirecting to a file.
I've just tried start /WAIT D:\pscp.exe -sftp -v -batch -pw password -ls [email protected]:/directory/subdirectory/subdirectory > c:\filelist.txt
and I also get an empty file however if I remove the start /WAIT
from the command line filelist.txt now contains the correct output.