i have to log into an sftp server to get multiple files.
im typing this post from a remote location and i dont have the script i wrote with me. but i got the sftp script to work by logging into the sftp server file by file. meaning, sftp to the server, "mget -p" or "get -p" one file at a time.
this obviously is not efficient.
i tried issuing the command "mget -p file1.txt file2.txt file3.txt". this doesnt seem to work. it can only get one file at a time apparently.
is there something im doing wrong here? id like to be able to get multiple files at once without having to sftp to the server for each file.
I don't recognise the -p flag. The nearest I know is the -P flag of get which specified a local path to get the file from.
If the above doesn't help (and you don't want all the files) then fire off sftp and get a listing of the files back, then use this to loop round and get the ones you want. Using the -b flag of sftp as suggested by RudiC is probably the best option however you choose to get the files, and far better than manual commands or using a here document (essentially coded in-line input to a command)
Would you care to share what you have created so far and we can suggest improvements? I'm assuming that you have SSH keys generated and shared so that you have password-less authentication for the account you connect to.
EDIT: I have just tried in my test server as follows are the steps on same.
i- I have made password less sftp as mentioned above.
ii- Now run following script to get files from source server or put files into target server.
cat script.ksh
stp username@server_name << ENDSFTP
cd /home/singh
get *.txt
quit
ENDSFTP
So above code has logged into my target box and took the files(which have .txt extensions) with them to current directory successfully.
iii- Now let's take an example of putting the files to a target server as follows.
cat script.ksh
sftp user_name@server_name << ENDSFTP
cd /home/Singh_is_King
put *.xls
quit
ENDSFTP