0
1
I want to move all files in local directory to remote directory.
And I am using this code to achieve it
SOURCE_FILE=/var/www/oneserver/*
TARGET_DIR=/var/www/anotherServer
ARCHIEVEFILE=/var/www/archieveServer
/usr/bin/expect<<EOD
spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST
expect "password:"
send "$PASSWORD\r"
expect "sftp>"
send "put $SOURCE_FILE $TARGET_DIR\r"
expect "sftp>"
send "bye\r"
EOD
It works fine, but sometime it stops and only send some files.
I also want to move the already sent file to ARCHIEVEFILE by using mv command. But dont get idea how to move it. I can't use scp
because the remote server not allowed using basic port, and the only way is using sftp.
Can anybody help, please?
[EDIT]
the $ARCHIEVEFILE
is still the local server, just to backup/move so those files are not sent anymore with next cronjob
the TARGET_DIR
is the remote server.
What writing "move all files in local directory to remote directory" - Do you really want to move the files? Or do you actually want to copy them? – Martin Prikryl – 2018-04-19T07:17:09.287
Isn't whole your question only about moving the uploaded files to local archive folder - i.e. you question actually has nothing to do with SFTP at all? – Martin Prikryl – 2018-04-19T07:18:12.370
I update my question. Please have a look. The real problem I encounter with this script is it only send some files, not all files. – Al Kasih – 2018-04-19T07:43:58.007
"it only send some files" – Any error messages or logs? – Kamil Maciorowski – 2018-04-19T07:47:58.100
@Kamil No, When I run the bash script manually, it just stop after uploading the last file, which actually still there are some files left. – Al Kasih – 2018-04-19T07:48:33.170
I actually want to find out what is the problem. – Al Kasih – 2018-04-19T07:49:42.723
All files has similar contents and similar title format. – Al Kasih – 2018-04-19T07:51:09.760
Note: shell globbing and the quoting you use makes your code prone to errors related to spaces in filenames etc. I'm not sure it's the actual problem in this case though. – Kamil Maciorowski – 2018-04-19T07:53:04.297
To me, there are two possibilities why this happen. Lost connection or it tried send the same file again and terminate it --tha's why I want to make the
rm
command works. but therm
still didn't work there. – Al Kasih – 2018-04-19T07:54:52.323suggestion: configure ssh with keys( no passwords) and use scp in script :) – Drako – 2018-04-19T09:37:24.873