2014-12-06 66 views
0

我想通過FTP上傳文件,而不需要「複製」對話框,並且我希望在完成上傳文件時關閉腳本(因爲有上傳文件的睡眠時間,並且當我刪除它時代碼不會上傳文件)。如何在FTP上傳期間抑制「複製」窗口?

Set oShell = CreateObject("Shell.Application") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

path = "kll.bat" 
FTPUpload(path) 

Sub FTPUpload(path) 
    On Error Resume Next 

    Const copyType = 16 
    waitTime = 2000 
    FTPUser = "username" 
    FTPPass = "password" 
    FTPHost = "ftp.example.com" 
    strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost 

    set objFTP = oShell.NameSpace(strFTP) 

    If objFSO.FileExists(path) Then 
    set objFile = objFSO.getFile(path) 
    strParent = objFile.ParentFolder 
    Set objFolder = oShell.NameSpace(strParent) 
    Set objItem = objFolder.ParseName(objFile.Name) 
    objFTP.CopyHere objItem, copyType 
    End If 

    If Err.Number <> 0 Then 
    End If 

    WScript.Sleep waitTime 
End Sub 
+0

複製窗口的行是(objFTP.CopyHere objItem,copyType),我想讓它隱藏 – TheDrfifa 2014-12-06 09:49:52

+0

1.)爲什麼你的代碼不縮進? 2)你確定要在網上發佈實時用戶名和密碼嗎? – Tomalak 2014-12-06 10:00:27

+0

1)它是成功的工作,但有問題,我想有人解決它2)用戶是空的意思,如果任何機構破解它沒有一點與該 – TheDrfifa 2014-12-06 11:06:29

回答

0

按照該documentation,請嘗試更改copyType到20(16 + 4):

Sub FTPUpload(path) 
    On Error Resume Next 

    Const copyType = 20 'respond "Yes to All" & don't display progress dialog 
    waitTime = 2000 
    FTPUser = "username" 
    FTPPass = "password" 
    FTPHost = "ftp.example.com" 
    strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost 

    set objFTP = oShell.NameSpace(strFTP) 

    If objFSO.FileExists(path) Then 
    set objFile = objFSO.getFile(path) 
    strParent = objFile.ParentFolder 
    Set objFolder = oShell.NameSpace(strParent) 
    Set objItem = objFolder.ParseName(objFile.Name) 
    objFTP.CopyHere objItem, copyType 
    End If 

    If Err.Number 0 Then 
    End If 

    WScript.Sleep waitTime 
End Sub

如果不工作,你似乎已經遇到的其中標誌被忽略的情況之一。在這種情況下,您必須與對話一起居住,或切換到另一種上傳方式。一種選擇是與您的飛行產生FTP腳本運行ftp.exe

Set fso = CreateObject("Scripting.FileSystemObject") 

scriptfile = fso.BuildPath(fso.GetSpecialFolder(2), fso.GetTempName) 
Set f = fso.OpenTextFile(scriptfile, 2, True) 
f.WriteLine "USER " & FTPUser 
f.WriteLine "PASS " & FTPPass 
... 
f.WriteLine "QUIT" 
f.Close 

Set sh = CreateObject("WScript.Shell") 
sh.Run "ftp -n -s:""" & scriptfile & """ " & FTPHost 

fso.DeleteFile(scriptfile) 

或者你可以使用ActiveXperts' Network Component

+0

謝謝,這段代碼工作正常! – TheDrfifa 2014-12-07 23:14:49