求助:使用cURL的--ftp-create-dirs在SFTP连接中无法创建目录
--ftp-create-dirs Not Working Over SFTP Hey there, let’s dig into why your --ftp-create-dirs flag isn’t creating directories even though your SFTP authentication checks out (and you can browse existing files/dirs). Here are actionable steps to diagnose and fix this:
1. Confirm You’re Using the Flag with the Right Tool & Syntax
Different tools (like rsync, lftp, or curl) handle --ftp-create-dirs (or equivalent flags) differently:
- For
rsync: The--ftp-create-dirsflag only creates missing parent directories for the target file path—not empty directories on their own. You need to:- Include the flag before your source/target paths (order matters!)
- Specify a target path that includes the missing directory you want to create
- Example of a working command:
Thersync -avv --ftp-create-dirs ./local-document.pdf sftp://your-user@your-server:/existing-parent-dir/new-subdir/-vvadds verbose output to show exactly what rsync is trying to do.
- For
lftp: Usemirror --create-dirsfor directory syncs, orput --create-dirsfor single files instead of the generic--ftp-create-dirsflag.
2. Verify Remote Directory Permissions
Just because you can read files doesn’t mean you have write access to the parent directory where you’re trying to create new folders:
- Use your SFTP client to run
ls -ld /path/to/parent-dir(replace with your actual parent path) - Check that your SFTP user has write permission (the
wflag) on that parent directory. If not, you’ll need to ask the server admin to adjust permissions or assign you to the correct group.
3. Test Manual Directory Creation First
Rule out server-side restrictions by manually creating a directory via SFTP:
- Run
mkdir /path/to/parent-dir/new-test-dirdirectly in your SFTP session - If this fails, the issue is definitely a permission or server configuration problem (not the
--ftp-create-dirsflag itself) - If this works, the problem is with how you’re using the flag in your command.
4. Check for Relative Path Gotchas
If you’re using relative paths (e.g., new-dir instead of /full/path/to/new-dir), confirm your SFTP session’s default working directory first with pwd. Your relative path will be resolved against this directory—so if you’re trying to create a folder outside this default path, you’ll need to use an absolute path.
5. Enable Verbose Logging to Spot Hidden Errors
Add verbose flags to your command to see exactly what’s failing:
- For
rsync: Add-vor-vvto get detailed logs about directory creation attempts - For
curl(if using with SFTP): Add-vto see the full SFTP command exchange with the server
Look for lines like "skipping directory creation" or permission denied messages—these will point you straight to the root cause.
内容的提问来源于stack exchange,提问作者YTZ

