FTP directory Upload [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-25 08:56:55

问题


I'll try and make this quick and simple. It can be hard to search of information on something to your not 100% sure on how you would search for it.

So I have a small batch script create to execute powershell ftp access and log me in and all that fun stuff.

Basically it's a cron job to upload files to my FTP server when i need to in a heartbeat.

I have HOME server, and on a regular basis or when told to, I want my script to execute and be able to upload a directory from my HOME server to the REMOTE ftp server.

Here is the script i am using.

@echo off<br>
echo user yourusername> ftpcmd.dat<br>
echo yourpassword>> ftpcmd.dat<br>
echo bin>> ftpcmd.dat<br>
echo cd \folder>> ftpcmd.dat<br>
echo put %1>> ftpcmd.dat<br>
ftp -n -s:ftpcmd.dat yourservername<br>

so I've gathered that put %1 = filetoupload

so filename.bat (the script) filetoupload = put %1 but it gives me errors saying

Saying: so Put I:\Documents Return: Error opening local file I:\Documents

Local on the FTP server? or Local on my HOME server.

How do i make it so i can upload a chosen directory from my HOME server to the FTP REMOTE server instead of files one by one???

Thank you sincerly


回答1:


I am assuming %1 here refers to a directory to upload via FTP. You can instead use the batch for function/keyword to instead add many put directives, corresponding to files in your upload directory.

For example:

@echo off

echo user yourusername> ftpcmd.dat
echo yourpassword>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo cd \folder>> ftpcmd.dat

for %%f in (%1\*.*) do echo put "%%f">> ftpcmd.dat

ftp -n -s:ftpcmd.dat yourservername

and for the recursive edition:

@echo off

echo user yourusername> ftpcmd.dat
echo yourpassword>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo cd \folder>> ftpcmd.dat

for /R %1 %%f in (*.*) do echo put "%%f">> ftpcmd.dat

ftp -n -s:ftpcmd.dat yourservername


来源:https://stackoverflow.com/questions/28778577/ftp-directory-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!