I'm making an sftp-connection to a remote server. I want the result of an ls-command in a local file and the result of ls on another folder in another local file. Because everything has to go as fast a possible I wan't to do everyting in one connection.
The command I use is : psftp -v -batch -b batchfile.ftp @ACCOUNT@remoteserver
The batchfile.ftp contains the following :
lcd *local directory*
cd folder1
ls *.txt filename1.lst
cd ../folder2
ls *.txt filename2.lst
bye
running the command doesn't give any errors. The results are displayed in the terminalwindow. But the local files aren't build. I want to use these commands in a script and need the 2 files. Can anybody help? How can I create these files using 1 connection. (redirecting the output of the psft-command isn't a solution because I need 2 seperate files.)
I'm trying to solve my problem this way now but I'm stuck on the following :
How can I split a file in different files using variable linenumbers?
I have a variable "begin" that contains the linenumber where the split should start and a variable "end" that contains a linenumber where the split should end.
My code :
sed -n $begin,$start 'p' > file1.txt
doesn't work. I tried different variations of this with " ' / ....
Can you help me with this command? On the internet there are a lot of solutions to this problem but so far nothing works.
---------- Post updated at 11:18 ---------- Previous update was at 11:02 ----------
Look at lftp as an alternative to sftp. It is scriptable, can be used for various protocols including ftp, sftp and http, and ls can be redirected! So:
sftp stfp://joe@remote.com
cd dir1
ls > file1.txt
cd ../dir2
rels > file2.txt
should do what you want. Note the use of rels as ls is cached (although it may not matter if you change directory - best to experiment).
lftp may not be there by default, but it will be in the repository if you are using a Linux distro.