Sftp script to get multiple files at the same time
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.
Would you also consider something equivalent to:-
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.
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.
I hope this helps you. Enjoy learning
Thanks,
R. Singh
Last edited by RavinderSingh13; 12-21-2016 at 12:12 AM..
Reason: Added few examples of get and put of sftp successfully now for OP.
This User Gave Thanks to RavinderSingh13 For This Post:
I want to rename (move) multiple files on remote server. I tried the following command to move all TXT files from my_dir directory to /new_dir. But it does not work. Any help?
#!/bin/ksh
sftp -dev3 << ABC
cd my_dir
$(for i in TXT; do echo "ls *.$i" ; rename $x /new_dir/$x;... (1 Reply)
Hi :),
I am new to Unix and Shell Script
I have a urgent requirement, where i am new to shell script and Unix
my requirement is I have a files in a folder like
sales-prod-India-details.txt
sales-prod-japan-details.txt
sales-prod-china-details.txt
My SFTP server has ... (3 Replies)
Hi,
In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this?
I am using #!/bin/ksh
For eg: sftp user@host <<EOF
cd /path
get *.txt
rename *.txt *.txt.done
... (7 Replies)
Hi All,
I would like to sftp 2 files with a single command. I tried the below options,
sftp suer@test13:"/u01/home/oracle/SetDb.sh /u01/home/oracle/.profile" ./
But what actually happens is
Fetching /u01/home/oracle/SetDb.sh to /u01/home/oracle/.profile
/u01/home/oracle/SetDb.sh ... (3 Replies)
Hi,
I have a problem while ftp'ing zip files one after the other from linux source directory to a ftp host machine. here is the shell script:
#!/bin/ksh
dir=data/dir1/dir2 # this dir is linux source directory where zip files located.
rmtdir='/home/'
echo $dir
for i in /$dir/*; do
if ;... (7 Replies)
Greetings!
I'm looking for starting information for a shell script. Here's my scenario:
I have multiple folders(100) for example:
/www/test/applications/app1/logs
/www/test/applications/app2/logs
Within these folders there are log files files that need to be deleted after a month.
... (3 Replies)
Hi All,
I am using ncftpput in one of my c-shell script to upload files to a remote location. The source files keep coming continuosly and to upload each file ncftpput opens a new connection everytime. It means ncftp uploads the file1 than file2 than file3 .... There is gap 20-25 secs between... (10 Replies)
Hi Experts,
Please help me to write the expect script for uploading multiple files in one shot . Below is my program that I have written.
#!/usr/local/bin/expect -f #/home/kulbhushan/sftp_prog.sh
# procedure to attempt connecting; result 0 if OK, 1 otherwise
proc connect {passw} {
expect... (1 Reply)
I need to get multiple files from a windows server to a solaris server using sftp,
I tried it but only can get one file at a time ( I'm unable to use a wild card character using sftp) hoe do i do this.
any light on this is appreciated.
Ram. (3 Replies)
Hi,
I'm new to using the sftp command prompt within the unix shell (usually I just use an FTP windows program).
I've successfully connected to a remote server from within ssh. I've also been able to copy multiple files using the mget command
e.g. mget *.html
How do I copy all files,... (3 Replies)