"Couldn't stat remote file: No such file or directory": Using FTP in shell script from *nix to Win
sftp> cd C:\Users\Tech1\testserverbackup
Couldn't stat remote file: No such file or directory
This is due to FTP servers not having the concept of drive letters for mounts, as Windows systems do.
You can use pwd
to while connected to FTP to determine the directory you're currently in:
sftp> pwd
/C/Users/Tech1
...which shows that in your environment, the FTP administrator mapped a Windows C:
drive to a regular folder called C
within the FTP server (and mapped all the other mounted drives to folders).
Jacqlyn
Hello! I started Evil r Us because I was tired of the constant harassment that everyone faces on social media platforms from a small group. I decided to treat trolling like the spam problem it is and started imposing punishments on my social media platform for harassment and bullying. Making consequences for trolling greatly reduced trolling on the platform (surprise, right?). If you would like to donate, see our code, or contribute or contact us in any way about our products, please head to our website.
Updated on June 05, 2022Comments
-
Jacqlyn almost 2 years
I'm using a Bash script to backup my webfiles via FTP. As the title says, I have an Ubuntu webserver and am backing up to a Windows machine. I have an ssh program and FileZilla Server on the Windows machine, and can SSH and SFTP into it. The core of the script looks like this:
SRCDIR="C:\\Users\\Tech1\\testserverbackup" DATAIN="/var/www/html/" FILENAME="-r *" sshpass -e sftp -oBatchMode=no -b - ${USER}@${LANHOST} << EOF cd ${SRCDIR} lcd ${DATAIN} mkdir $(date -I) cd $(date -I) put ${FILENAME} bye echo made it EOF
The others vars are a bit sensitive, so I don't want to post them, but the credentials have been working for me so far.
The error I'm getting looks like this:
sftp> cd C:\Users\Tech1\testserverbackup Couldn't stat remote file: No such file or directory
I've ssh'd into the folder and sftp'd, so I'm not really sure what the issue is. AFAIK, cd is the native windows command, not just the FTP one.
Any ideas what's going wrong? Thank you.
-
admdrew almost 10 yearsFTP hosts do not have the concept of mounted drives, as Windows systems do. As the error says, there is no file/directory with
C:
in the path while connecting via FTP. -
admdrew almost 10 yearsIt means that when you're connected via FTP (ie, on the
sftp>
prompt), there isn't aC:
drive to connect to, so trying tocd
to that path simply won't work. -
admdrew almost 10 years
cd
isn't Windows-specific, that's not the problem. UsingC:
as part of the file/folder path is Windows-specific, and has no meaning when on an FTP host. -
admdrew almost 10 yearsYou can still use absolute paths, but when connecting to an FTP host, it likely uses the Linux/Unix convention, so it likely starts with
/
(like the path in your$DATAIN
variable). -
Jacqlyn almost 10 yearsReplacing
C:\
with/
returns the same error. -
admdrew almost 10 yearsYes, the entire path is probably incorrect. What's your output when you type just
pwd
while logged into FTP? -
Jacqlyn almost 10 yearsAh, good point. It's /C/Users/Tech1, so that's what I'll use. Thank you for your help.
-
admdrew almost 10 yearsAhhh ok perfect, that makes sense. Glad to help!
-
Jacqlyn almost 10 years@admdrew Interesting, so that means that
/
is aboveC
, and going there, I can view all mounted drives. -
admdrew almost 10 yearsYes,
/
is the top-level/root folder. In your environment, the FTP administrator mapped a WindowsC:
drive to a regular folder calledC
within the FTP server (and mapped all the other mounted drives to folders). -
glenn jackman almost 10 years@jfa, you should answer your own question and accept it, so that others who have the same question don't have to pore through the comments.
-