Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: rdmm en 8 Enero 2015, 09:57 am



Título: Ayuda vbscript: envío de archivos ftps
Publicado por: rdmm en 8 Enero 2015, 09:57 am
Hola,
tengo un script hecho para mandar archivos por ftp y me funciona perfectamente.

Es este:

Código:
Código:
'****************FTP Upload
'Upload a file/folder to an FTP server


Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 MiMes=Month(Now)
strDate2=ucase(MonthName(MiMes))
strDate = Day(Date()) &"_"&   ucase(MonthName(MiMes))
'Path to file or folder to upload
path = "C:\archivos\archivoftp_"&strDate&".csv"

FTPUpload1


Sub FTPUpload1
if Time()>TimeValue("04:00:00") and Time()<TimeValue("04:45:00")Then
 MiMes=Month(Now)
strDate2=ucase(MonthName(MiMes))
strDate = Day(Date()) &"_"&   ucase(MonthName(MiMes))

On Error Resume Next

'Copy Options: 16 = Yes to All
Const copyType = 16

'FTP Wait Time in ms
waitTime = 80000
 
FTPUser = "user"
FTPPass = "pass"
FTPHost = "ftphost"
FTPDir = "/archivos"

strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)

'Make new folder on FTP site
'objFTP.NewFolder "FTP Backup"


'Upload single file       
If objFSO.FileExists(path) Then

Set objFile = objFSO.getFile(path)
strParent = objFile.ParentFolder
Set objFolder = oShell.NameSpace(strParent)

Set objItem = objFolder.ParseName(objFile.Name)

Wscript.Echo "Uploading file " & objItem.Name & " to " & strFTP
 objFTP.CopyHere objItem, copyType


End If


'Upload all files in folder
If objFSO.FolderExists(path) Then

'Code below can be used to upload entire folder
Set objFolder = oShell.NameSpace(path)

Wscript.Echo "Uploading folder " & path & " to " & strFTP
objFTP.CopyHere objFolder.Items, copyType

End If


If Err.Number <> 0 Then
Wscript.Echo "Error: " & Err.Description
End If

'Wait for upload
WScript.Sleep waitTime
End if
End Sub
Ahora necesito hacerlo para mandar archivos por ftps tcp/990 pero todavía no lo he conseguido, a ver si recibo una ayudita!

Qué tengo que cambiar de este script para poder subir por ftps tcp/990 ?
gracias


Título: Re: Ayuda vbscript: envío de archivos ftps
Publicado por: BlackM4ster en 8 Enero 2015, 12:00 pm
Código
  1. strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir

Ahí haces una petición ftp usando el puerto estándar

Código
  1. strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & ":990" &  FTPDir

Ahí especificas un puerto


Al final el estándar es:
Código:
servicio://usuario:pass@maquina.dominio:puerto/directorio/fichero.extension


Título: Re: Ayuda vbscript: envío de archivos ftps
Publicado por: rdmm en 8 Enero 2015, 15:08 pm
Hola,
en primer lugar muchas gracias por tu ayuda pero no me funciona lo que me has puesto.


He probado también con:
strFTP = "ftps://" & FTPUser & ":" & FTPPass & "@" & FTPHost & ":990" &  FTPDir

POniendo ftps en vez de fpt pero tampoco ha funcionado.



Título: Re: Ayuda vbscript: envío de archivos ftps
Publicado por: BlackM4ster en 8 Enero 2015, 19:00 pm
Entonces quizas deberias buscar otro código que haga la peticion de otra forma, ya que por petición de navegador creo que es esa la unica forma de cambiar el puerto. A ver si alguien sabe


Título: Re: Ayuda vbscript: envío de archivos ftps
Publicado por: rdmm en 9 Enero 2015, 08:26 am
Gracias. A ver si alguien más me puede ayudar. Saludos.


Título: Re: Ayuda vbscript: envío de archivos ftps
Publicado por: 79137913 en 9 Enero 2015, 14:33 pm
HOLA!!!

Te dejo una funcion mia con winsocks virtuales ;)

No me culpen por usar magia negra en VBS  >:D

Código
  1. 'FTP
  2.    Dim FTPData
  3.    Dim FTPCOMPLETE
  4.    Dim W1
  5.    Dim W2
  6. '/FTP
  7.  
  8.  
  9. Set W1 = WScript.CreateObject("MSWINSOCK.Winsock", "W1_")
  10. Set W2 = WScript.CreateObject("MSWINSOCK.Winsock", "W2_")
  11. Call FTPUpload(FTPServer, FTPPort, FTPUser, FTPPass, SPath, SFile)
  12. Set W1 = Nothing
  13. Set W2 = Nothing
  14.  
  15. Function FTPUpload(FTPServer, FTPPort, FTPUser, FTPPass, SPath, SFile)
  16.    W1.RemoteHost = FTPServer
  17.    W1.RemotePort = FTPPort
  18.    W1.Connect
  19.    If WaitResponse Then Exit Function
  20.    If FTPCODE <> 220 Then Exit Function
  21.        FTPData = ""
  22.        W1.SendData "USER " & FTPUser & vbCrLf
  23.        If WaitResponse Then Exit Function
  24.    If FTPCODE <> 331 Then Exit Function
  25.        FTPData = ""
  26.        W1.SendData "PASS " & FTPPass & vbCrLf
  27.        If WaitResponse Then Exit Function
  28.    If FTPCODE <> 230 Then Exit Function
  29.        FTPData = ""
  30.        W1.SendData "PASV" & vbCrLf
  31.        If WaitResponse Then Exit Function
  32.    If FTPCODE <> 227 Then Exit Function
  33.        Dim Aux
  34.        Aux = Split(FTPData, ",")
  35.        FTPDataPort = (Aux(UBound(Aux) - 1) * 256) + Left(Aux(UBound(Aux)), InStr(Aux(UBound(Aux)), ")") - 1)
  36.        FTPDataIP = Trim(Replace(Right(Aux(0), 3), "(", vbNullString)) & "." & Aux(1) & "." & Aux(2) & "." & Aux(3)
  37.        FTPData = ""
  38.        W1.SendData "STOR " & SFile & vbCrLf
  39.        W2.RemotePort = FTPDataPort: W2.RemoteHost = FTPDataIP
  40.        W2.Connect
  41.        WaitResponse
  42.    If Not (FTPCODE = "125" Or FTPCODE = "150") Then Exit Function
  43.        FTPUpload = SPath & "\" SFile
  44. End Function
  45.  
  46. Function Upload(FilePath)
  47.    Dim UPFile
  48.    Dim FileLen
  49.    Dim TotalSent
  50.    Dim a
  51.    Set a = WScript.CreateObject("ADODB.Stream")
  52.    a.open
  53.    a.Type = 1
  54.    a.LoadFromFile (FilePath)
  55.    UPFile = a.Read()
  56.    FTPCOMPLETE = False
  57.    W2.SendData UPFile
  58.    EsperaSubida = 0
  59.    Do
  60.        WScript.Sleep 1000
  61.        EsperaSubida = EsperaSubida + 1
  62.        If SendIsComplete = 1 Then Upload = True: Exit Function
  63.        If EsperaSubida > 300 Then Exit Function
  64.    Loop
  65. End Function
  66.  
  67. Sub W1_DataArrival(ByVal bytesTotal)
  68.    W1.GetData FTPData, 8
  69. End Sub
  70.  
  71. Function SendIsComplete()
  72.    SendIsComplete = FTPCOMPLETE
  73. End Function
  74.  
  75. Sub w2_SendComplete()
  76.    FTPCOMPLETE = 1
  77. End Sub
  78.  
  79. Function WaitResponse()
  80.    Espera = 0
  81.    Do
  82.        WScript.Sleep 1000
  83.        Espera = Espera + 1
  84.        If Espera > 10 Then WaitResponse = 1: Exit Function
  85.        If FTPCODE <> 0 Then Exit Function
  86.    Loop
  87. End Function
  88.  
  89. Function FTPCODE()
  90.    If Len(FTPData) > 3 Then FTPCODE = Left(FTPData, 3) Else FTPCODE = 0
  91. End Function

GRACIAS POR LEER!!!