Hej.
Er der nogle der har erfaring med WSCRIPT.SHELL i asp classic?
Jeg har følgende function
- Function FTPUpload(ftpsite, sUsername, sPassword, sLocalFile, sRemotePath)
-
- Dim objFSO, objTextFile, oScript, oScriptNet, oFileSys, oFile, strCMD, strTempFile, strCommandResult
- Dim ftp_address, ftp_username, ftp_password, ftp_physical_path, ftp_files_to_put
-
- ' Edit these variables to match your specifications
- ftp_address = ftpsite
- ftp_username = sUsername
- ftp_password = sPassword
- ftp_remote_directory = sRemotePath ' Leave blank if uploading to root directory
- ftp_files_to_put = sLocalFile 'Server.MapPath("/importexport/getRemoteRates.xml") ' You can use wildcards here (e.g. *.txt)
- On Error Resume Next
- Set oScript = Server.CreateObject("WSCRIPT.SHELL")
- Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- ' Build our ftp-commands file
- Set objTextFile = objFSO.CreateTextFile(Server.MapPath("test.ftp"))
-
- objTextFile.WriteLine "lcd " & Server.MapPath(".")
- objTextFile.WriteLine "open " & ftp_address
- objTextFile.WriteLine ftp_username
- objTextFile.WriteLine ftp_password
-
-
-
- ' Check to see if we need to issue a 'cd' command
- If ftp_remote_directory <> "" Then
- objTextFile.WriteLine "mkdir " & ftp_remote_directory
- objTextFile.WriteLine "cd " & ftp_remote_directory
- End If
-
- objTextFile.WriteLine "prompt"
- ' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the following line
- objTextFile.WriteLine "binary"
- ' If there are multiple files to put, we need to use the command 'mput', instead of 'put'
- If Instr(1, ftp_files_to_put, "*",1) Then
- objTextFile.WriteLine "mput " & ftp_files_to_put
- Else
- objTextFile.WriteLine "put " & ftp_files_to_put
- End If
- objTextFile.WriteLine "bye"
- objTextFile.Close
- Set objTextFile = Nothing
-
- ' Use cmd.exe to run ftp.exe, parsing our newly created command file
- strCMD = "ftp.exe -s:" & Server.MapPath("/test/test.ftp")
- strTempFile = "C:\" & oFileSys.GetTempName( )
- ' Pipe output from cmd.exe to a temporary file (Not :| Steve)
- Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)
- Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)
-
- On Error Resume Next
- ' Grab output from temporary file
- strCommandResult = Server.HTMLEncode( oFile.ReadAll )
- oFile.Close
- ' Delete the temporary & ftp-command files
- Call oFileSys.DeleteFile( strTempFile, True )
- Call objFSO.DeleteFile( Server.MapPath("test.ftp"), True )
- Set oFileSys = Nothing
- Set objFSO = Nothing
- ' Print result of FTP session to screen
- 'Response.Write( Replace( strCommandResult, vbCrLf, "<br>", 1, -1, 1) )
-
- FTPUpload = strCommandResult
-
- End Function
Det virker fint til at uploade filer til en normal ftp. Men jeg ville god bruge det til at uploade til en secure ftp(SFTP) er der nogle der kan hjælpe mig i den rigtige retning her? er helt på bar bund.
Indlæg senest redigeret d. 03.02.2012 15:12 af Bruger #13770