Expect SFTP Rename
Hey Guys,
Having a bit of trouble trying to get an Expect script to do something simple! I need to rename a file after I've downloaded it, and although I've probably gone the long way round I've got an 'almost' working solution. I download the files, and then do an ls and pass the contents to a variable, then find the files within that variable and run through each line in a loop... the problem is with the rename command: Code:
/usr/bin/expect <<! > $FTPLIST If I substitute the $i for the actual filename in txt it works fine, but as soon as I add the $i it tries to send the command immediately after the first $i and therefore the SFTP Session just moans that the rename command is unfinished. Anyone have any ideas? Thanks Jon |
if the rename subcommand does what i think it does this would probably be simpler:
Code:
ssh user@host mv /whatever/floats /your/boat |
Unfortunately ssh is not an option. We have no ssh access to the server. The server belongs to someone else, and we have access only via SFTP.
I would have preferred not to use Expect for this at all, but unfortunately I've no other option really. |
Just a quick bump wondering if anyone has any ideas?
I don't understand why if I send the following command in my expect script: Code:
send "rename file1 processed_file1" But when I do it with the loop: Code:
awk '/MF_BAT/' $FTPLIST | while read i; do Code:
sftp> cd Output If anyone has any ideas, it would be greatly appreciated. Thanks Jon |
maybe there is a \n character at the end of the file you are reading in. (did you by chance create the file on windows ?)
|
Not sure what you mean by the file I'm reading in? There's a chance the file was created by a windows box, but I'm not calling in the file really, I'm just renaming it on the remote SFTP server.
|
what is $FTPLIST ?
|
It's a file I'm writing the output of the SFTP session to.
|
output ?; you seem to be reading it in to your while loop via a pipe| ?
what is the output of: Code:
cat -A $FTPLIST |
Sorry I've not been clear..
So, before the bit of the script I've posted, theres another SFTP session that logs onto the server, and carries out the command ls -1 *.JPEG.PGP Because the output of the whole session is written to $FTPLIST, the next bit finds all filenames that start with MF_BAT. Then I want to loop through those filenames and rename them |
We sort of need to know what the contents are - Something appears to be including a newline as part of a file name.
|
the result is:
Code:
spawn sftp -oPort=22 Login@XX.XX.XX.XX^M$ |
is MF_BAT_BB160914192302.csv.PGP the only file you are having problems with ?
where is it in $FTPLIST (first line / last line ?) |
Quote:
seems like you are sending \r in the previous iteration. |
That would make sense as the above is the output of this:
Code:
/usr/bin/expect <<! > $FTPLIST |
All times are GMT -5. The time now is 06:44 AM. |