0

I Have a list file File_Transfer_List.txt which contains list of file to do scp

My requirement is I need to do scp that files given in the list file and then delete the files from source location.

I tried this :

scp File_Name user@server:/destination && rm File_Name ;

I am unable to test it, I don't have my scp ready to test it; can any one correct me if I am wrong.

  • You said you tried that but immediately afterwards you said you are unable to test it. Which is it? In any case, for anything that involves deleting files (and could therefore be dangerous), the best advice for you is just to test it yourself. You can easily create a dummy throwaway file with unimportant data to see if your command works. When you test it, you will know whether or not it works, and you will not need to ask here if the command is OK! – Celada May 13 '15 at 18:09
5

You have two requirements here (files from filelist and remove source files) that scream for using rsync.

Depending on what your filelist contains (relative or absolute paths, preserve paths on backup, etc) you could just do:

rsync --files-from=filelist.txt --remove-source-files -avz \
      . user@remotehost:/path/to/backup/folder
  • ya tried it, it is wrking when both the servers in Unix.... – deepuu May 14 '15 at 7:19
  • @deepu, if this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. – terdon May 14 '15 at 9:41
0

If I understand correctly, you have a file tat contains file names and you want to copy each of those files to the remote server and delete the local one if the copy was successful. If so, you can do:

while read file; do 
    scp "$file" user@remote.com:/remote/path && rm "$file" 
done < files.txt
  • Ya almost same, My List file is on unix Server and I shuled read list file and after copying the files from windows to unix and then i shuled delete the files from windows server – deepuu May 14 '15 at 7:18
  • @deepuu I don't understand, if the files are on Windows, then this won't work. – terdon May 14 '15 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.