Visit Our UNIX and Linux User Community

Help with moving files on remote server using sftp

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with moving files on remote server using sftp
# 1  
Old 04-18-2016
Help with moving files on remote server using sftp

I need to sftp a file ABC_sysdate.csv (File name with system date and timestamp) to a temporary directory on the remote server and once the file is copied I've to move the file from temporary directory to the main directory with the same name.
I have to generate a new file every hour and repeat the sftp process.How can I do that using a unix script?
# 2  
Old 04-18-2016
scp is an ssh client that does file copies and file moves on remote systems. Generally if you have sftp access, and are not in a chroot jail on the remote, you can do this also assuming ssh keys and permissions are correctly set on remotebox:

scp remotebox:/path/to/file/filename remotebox:/tmp/path/filename
sftp remotebox <<! EOF
   mkdir /path/to/new/file/
scp remotebox:/tmp/path/filename  remotebox:/path/to/new/file/filename

# 3  
Old 04-18-2016
Thanks for the response Jim.

I don't have permissions to create directory on the remote server. I need to place a file from unix server using sftp to temporary directory and move all the files to another directory.

Is there any alternate option?
# 4  
Old 04-19-2016
Well if your destination directory already exists then simply scp the file and then use ssh to move it:

scp -p ABC_sysdate.csv remotebox:/tmp/
ssh remotebox "mv /tmp/ABC_sysdate.csv /path/to/new/file/"

# 5  
Old 04-19-2016
Hi Chubler,

Thanks for your response but I don't have ssh access, all I have is sftp access.

First I need to sftp the file from my linux box to temporary directory on the remote server and then move the file to main directory on the remote server.

Also, can we use *.csv while moving the file because the timestamp on the file name keeps on changing?
# 6  
Old 04-19-2016
Unfortunately, I am unaware of any mechanism of moving remote files using sftp. Perhaps you could transfer them to a "intransit" name in the destination directory and then rename, this is what rsync does.

scp -p ABC_sysdate.csv remotebox:/upload/path/.intransit.ABC_sysdate.csv
sftp remotebox <<EOF
   rename /upload/path/.intransit.ABC_sysdate.csv /upload/path/ABC_sysdate.csv 

The -p option of scp should preserve permissions and file times
# 7  
Old 04-19-2016
Yes you can use *.csv.
Can you have someone who has access to the remote server, create a cron job that moves any files in your inbound directory to the place where they need to be. Alternatively, can the inbound directory that you have access to be soft linked to the final destination directory.

Previous Thread | Next Thread
Test Your Knowledge in Computers #837
Difficulty: Medium
SOAP was designed as an object-addressing protocol in 1998,
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename (move) multiple files on remote server using sftp

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)
Discussion started by: Soham
1 Replies

2. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

3. Shell Programming and Scripting

Test if Remote server is up and running before SFTP'ing files (in batch mode)

Hello, In our Data Warehouse environment, before our batch SFTP jobs kick off to pull the files from remote servers, I would like to setup a pre-sftp job that would test if all the remote servers from where the files are being pulled, are up and running. If any one of the remote serer is... (2 Replies)
Discussion started by: Dippu
2 Replies

4. UNIX for Advanced & Expert Users

SFTP from remote server

Hi All,While sftp from remote server an error (/) is coming before the file in a script.Please find the below log. The file is on home directory on remote server. (6 Replies)
Discussion started by: kiranparsha
6 Replies

5. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

6. UNIX for Dummies Questions & Answers

Get filelist.txt from a sftp remote server

Hi everyone, so I have a script create a login file to log into the sftp remote server, go to a certain directory and get the list of files in that direction into a text file in another folder (local folder). Here is the piece of code echo "#!/usr/local/bin/expect -f" >>... (5 Replies)
Discussion started by: warmboy610
5 Replies

7. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

8. Programming

SFTP from one remote server to another remote server from desktop

Hi, I have 1. lappy 2. server A 3. server B Now, what i need is to run a command from lappy that will sftp a file from server A to server B. Please guide me to achieve this. -akash (1 Reply)
Discussion started by: akash.mahakode
1 Replies

9. Shell Programming and Scripting

SFTP setting with a remote server - need help

Hi All, i want to setup a STPF setting to a remote server. Could you please help on this. The setting i have done but its still asking for password. Could anyone throw some light on the same? Thanks in advance. Pankaj (1 Reply)
Discussion started by: panknil
1 Replies

10. UNIX for Dummies Questions & Answers

Moving files between directories using SFTP

I want to connect to an SFTP server, GET some files, then move those files to a different directory on the SFTP server so I don't try to GET them next time. But there doesn't seem to be a way to move files between directories on the remote server from SFTP. I missing something obvious? And if... (6 Replies)
Discussion started by: cjhancock
6 Replies

Featured Tech Videos