创建目录或跳过ftp脚本

时间:2016-07-02 13:31:45

标签: linux batch-file ftp

我正在使用Adrive.com帐户上传备份文件。我不知道安装的linux版本。我尝试使用这些命令获取版本:

ftp> uname -r
Invalid command.
ftp> cat /etc/*-release
Invalid command.
ftp> lsb_release -a
Invalid command.
ftp> cat /proc/version
Invalid command.
ftp> uname -a
Invalid command.

你可以看到它们都没有用。

这是我正在尝试运行的脚本:

ECHO open ftp://xxx:xxxx@ftp.adrive.com>FTPSND.TXT
echo cd backup>>FTPSND.TXT
echo cd companyfiles>>FTPSND.TXT
echo mkdir %3>>FTPSND.TXT
echo cd %3>>FTPSND.TXT
echo option transfer binary>>FTPSND.TXT
ECHO send %1>>FTPSND.TXT
ECHO close>>FTPSND.TXT
ECHO exit>>FTPSND.TXT
winscp.com /script=ftpsnd.txt >>%2

mkdir上发生的错误:

Error creating folder 'BEL'.
File or directory already exists.
(A)bort, (R)etry, (S)kip: Abort

我的主要问题是,如果目录不存在,我需要创建它,否则我跳过该步骤继续发送。

我是如何解决这个问题的?

修改

回应Hackoo:

我没有提到这个批处理文件是从靠近末尾的另一个批处理文件中调用的。当我使用你的代码时,我没有上传文件,日志显示:

ftp> Open ftp.adrive.com
Connected to ftp.adrive.com.
220 Username is your email address used for web interface
User (ftp.adrive.com:(none)):
331 Username OK, please send password.

230 Welcome xxxxx
ftp> prompt n
Interactive mode Off .
ftp> bin
200 TYPE changed to I.
ftp> MkDir /backup/companyfiles/IFC
550 File or directory already exists.
ftp> cd /backup/companyfiles/IFC
250 Changed directory OK.
ftp> mput D:\SSSAVES\sssbackup\TMPDIR\IFC_20160705141154.ZIP
200 PORT command OK.
150 Opening BINARY mode data connection for file IFC_20160705141154.ZIP.

从这一点开始并没有做任何事情。我让它坐在那里2个小时,以确保。该文件的大小只有70mb,所以我怀疑它会花那么长时间。

编辑#2

该文件最终出现在Adrive上,所以我相信ftp mput正在运行。它发送后似乎没有释放

编辑#3

我确实将它从mput更改为put,因为我只发送了1个文件。这没有什么区别。

2 个答案:

答案 0 :(得分:1)

我在 ADrive.com 上创建了一个帐户,我创建了这个脚本,只是试一试

@echo off
Title Multiple file Upload by Hackoo on adrive
Color 0A
::****** Settings for FTP ************
Set FTPSERVER=ftp.adrive.com
Set USER=Your Login
Set Password=Your Password
Set LocalFolder=C:\Hackoo
Set RemoteFolder=/backupFolder
::************************************
::--- FTP commands below here ---
> ft.do echo Open %FTPSERVER%
>> ft.do echo %USER%
>> ft.do echo %Password%
>> ft.do echo prompt n
>> ft.do echo bin
>> ft.do echo lcd %LocalFolder%
>> ft.do echo MkDir %RemoteFolder%
>> ft.do echo cd %RemoteFolder%
>> ft.do echo mput "*.*"
>> ft.do echo disconnect
>> ft.do echo bye
::************************************
ftp -s:ft.do
del ft.do
Pause

答案 1 :(得分:0)

你可以尝试使用这个vbscript并告诉我它是否上传了70Mb大小的文件:

set objShell = CreateObject("WScript.Shell")
Login = "Your Username"
'If your username contains the @ symbol, and your web browser does not support this, you can substitute for the +
Login = Replace(Login,"@","+")
Password = "Your Pass"
FTPSERVER = "ftp.server.com"
RemoteFolder = "RemoteFolderName"
FTPURL = "ftp://"& Login &":"& Password &"@"& FTPSERVER &"/"& RemoteFolder
Connect2FTP = objShell.run("Explorer "& FTPURL ,1,False)

我做了一个旧的vbscript就像那样处理

说明:

与朋友或网吧相比,您所在的电脑与您不同? 您想在FTP服务器上添加,修改,删除文件或文件夹吗? 没有机会,你没有像FTP客户端那样的程序(FileZilla,CuteFTP,FlashFXP等等)来访问你的私人FTP服务器! 没问题=> FTP Explorer是在FTP客户端中打开Web浏览器或Windows资源管理器的解决方案!

我只是将这个古老的法语版翻译成英文版!

希望能帮到你!

enter image description here

Titre = "FTP EXPLORER © Hackoo © 2016"
    Set objIE = CreateObject( "InternetExplorer.Application" )
    objIE.Navigate "about:blank"
    objIE.Document.Title = Titre
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 320
    objIE.Height         = 390
    ScreenWidth = objIE.document.ParentWindow.screen.width 
    ScreenHeight = objIE.document.ParentWindow.screen.height
    objIE.Left = (ScreenWidth  - objIE.Width ) \ 2
    objIE.Top  = (ScreenHeight - objIE.Height) \ 2
    Do While objIE.Busy
        WScript.Sleep 200
    Loop
    objIE.Document.Body.InnerHTML = "<div align=""center""><p><h3 style='color:Red'>UserName " _
    & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    & "id=""Login"" value=""put your user name here""></h3></p>"_
    & "</p><p><h3 style='color:Red'>Password<br><input type=""password"" style='color:Blue' value=""Put your password here"" size=""20"" " _
    & "id=""Password""></h3></p><p><input type=" _
    & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
    & "<h3 style='color:Red'>FTP Server " _
    & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    & "id=""FTPSERVER"" value=""ftp.server.com""></h3>"_
    & "<br><h3 style='color:Red'>Remote Folder "_
    & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    & "id=""DossierDistant"" value=""/www""></h3></p>"_
    & "<input type=""submit"" value="" Browse your FTP Folder"" " _
    & "onclick=""VBScript:OK.Value=1""></p></div>"
    objIE.Document.Body.Style.overflow = "auto"
    objIE.Document.body.style.backgroundcolor="lightGreen"
    objIE.Visible = True
    objIE.Document.All.Password.Focus
    On Error Resume Next
    Do While objIE.Document.All.OK.Value = 0
        WScript.Sleep 200
        If Err Then    
            IELogin = Array( "", "" )
            objIE.Quit
            Set objIE = Nothing
            wscript.quit
        End if
    Loop
    On Error Goto 0
    Set ws = CreateObject("wscript.Shell")
    Login = objIE.Document.All.Login.Value
    Login = Replace(Login,"@","+")'If your username contains the @ symbol, and your web browser does not support this, you can substitute for the +
    Password = objIE.Document.All.Password.Value
    FTPSERVER = objIE.Document.All.FTPSERVER.Value
    DossierDistant = objIE.Document.All.DossierDistant.Value
    URL = "ftp://"&Login&":"&Password&"@"&FTPSERVER&"/"&DossierDistant
    Connect2FTP = ws.run("Explorer "& URL ,1,False)
    objIE.Quit
ws.Popup "Connecting to "&qq(FTPSERVER)&" is in progress ..........",3,"Connecting to "&qq(FTPSERVER)&" is in progress ..........",64
    Set objIE = Nothing
    Set ws = Nothing
    Close("iexplore.exe")
'****************************************************
Sub Close(Process)
    Set Ws = CreateObject("Wscript.Shell")
    Command = "cmd /c Taskkill /F /IM "&Process&""
    Execution = Ws.Run(Command,0,True)
End Sub
'****************************************************
Function qq(strIn) 
    qq = Chr(34) & strIn & Chr(34)
End Function
'****************************************************