VBS-Linux
Würden Sie gerne auf diese Nachricht reagieren? Erstellen Sie einen Account in wenigen Klicks oder loggen Sie sich ein, um fortzufahren.

Sie sind nicht verbunden. Loggen Sie sich ein oder registrieren Sie sich

Dateien auf FTP hochladen bzw. Aktualisieren

3 verfasser

Nach unten  Nachricht [Seite 1 von 1]

Niklas Admin

Niklas Admin
Admin

Ich habe mal eine Frage. Google gibt zwar antworten, aber zu viele unterschiedliche. Man kann ja via Visual Basic Daten auf einen FTP Server laden. Aber welche Methode ist da die beste, denn wie gesagt Google gibt mir da viele Lösungen aus.

http://vbs-linux.dbzworld.org

Trojan

Trojan

Was genau meinst du mit VB-Daten? Quellcode oder ausführbare Programme?

Niklas Admin

Niklas Admin
Admin

Von Visual Basic gar nichts, ich möchte nur mit Visual Basic ein Programm machen worin ich auswählen kann welche Dokumente upgedatet werden sollen, also auf dem Webspace geladen werden und überschrieben werden.

http://vbs-linux.dbzworld.org

Trojan

Trojan

Nimm doch den Firefox mit der Erweiterung FireFTP.

Niklas Admin

Niklas Admin
Admin

Das ist nicht sinn und zweck meiner Idee, ansonsten nutze ich ja File Zilla, aber ich würde halt auch gerne den richtigen Code in VB dafür haben. Ist es in Ordnung, wenn man schreibt My.Computer.Network.UploadFile(Values)?
Oder gibt es da elegantere Lösungen?

http://vbs-linux.dbzworld.org

thecaptain

thecaptain

Code:
' Download a remote file to a local file name and include a path. Then, set the
' resume flag. The local file name will be created or will be overwritten, but the path must exist.
Public Sub DownloadFile(ByVal sFileName As String, _
ByVal sLocalFileName As String, _
ByVal bResume As Boolean)
Dim st As Stream
Dim output As FileStream
Dim cSocket As Socket
Dim offset, npos As Long

SetBinaryMode(True)

If (sLocalFileName.Equals("")) Then
sLocalFileName = sFileName
End If

If (Not (File.Exists(sLocalFileName))) Then
st = File.Create(sLocalFileName)
st.Close()
End If

output = New FileStream(sLocalFileName, FileMode.Open)
cSocket = CreateDataSocket()
offset = 0

If (bResume) Then
offset = output.Length

If (offset > 0) Then
'Send an FTP command to restart.
SendCommand("REST " & offset)
If (m_iRetValue <> 350) Then
offset = 0
End If
End If

If (offset > 0) Then
npos = output.Seek(offset, SeekOrigin.Begin)
End If
End If
'Send an FTP command to retrieve a file.
SendCommand("RETR " & sFileName)

If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
m_iBytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
output.Write(m_aBuffer, 0, m_iBytes)

If (m_iBytes <= 0) Then
Exit Do
End If
Loop

output.Close()
If (cSocket.Connected) Then
cSocket.Close()
End If

ReadReply()
If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

End Sub

bzw.

' This is a function that is used to upload a file from your local hard disk to your FTP site
' and then set the resume flag.
Public Sub UploadFile(ByVal sFileName As String, _
ByVal bResume As Boolean)
Dim cSocket As Socket
Dim offset As Long
Dim input As FileStream
Dim bFileNotFound As Boolean

cSocket = CreateDataSocket()
offset = 0

If (bResume) Then
Try
SetBinaryMode(True)
offset = GetFileSize(sFileName)
Catch ex As Exception
offset = 0
End Try
End If

If (offset > 0) Then
SendCommand("REST " & offset)
If (m_iRetValue <> 350) Then

'The remote server may not support resuming.
offset = 0
End If
End If
'Send an FTP command to store a file.
SendCommand("STOR " & Path.GetFileName(sFileName))
If (Not (m_iRetValue = 125 Or m_iRetValue = 150)) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

'Check to see if the file exists before the upload.
bFileNotFound = False
If (File.Exists(sFileName)) Then
' Open the input stream to read the source file.
input = New FileStream(sFileName, FileMode.Open)
If (offset <> 0) Then
input.Seek(offset, SeekOrigin.Begin)
End If

'Upload the file.
m_iBytes = input.Read(m_aBuffer, 0, m_aBuffer.Length)
Do While (m_iBytes > 0)
cSocket.Send(m_aBuffer, m_iBytes, 0)
m_iBytes = input.Read(m_aBuffer, 0, m_aBuffer.Length)
Loop
input.Close()
Else
bFileNotFound = True
End If

If (cSocket.Connected) Then
cSocket.Close()
End If

'Check the return value if the file was not found.
If (bFileNotFound) Then
MessageString = m_sReply
Throw New IOException("The file: " & sFileName & " was not found." & _
" Cannot upload the file to the FTP site.")

End If

ReadReply()
If (Not (m_iRetValue = 226 Or m_iRetValue = 250)) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If
End Sub

ist aber ungetestet.
habs in nem forum gefunden.

schaus dir an und probier dich Wink

Niklas Admin

Niklas Admin
Admin

Na ja über das mit eleganter kann man jetzt reden, da das definitiv mehr als eine Zeile ist. Ich werde es aber trotzdem testen und dann vllt. zur Klasse umschreiben, damit ich insgesamt im Form Code weniger habe und das ganze auch für andere Projekte nutzen kann, aber wie gesagt ich werde es erst einmal testen.

http://vbs-linux.dbzworld.org

Gesponserte Inhalte



Nach oben  Nachricht [Seite 1 von 1]

Befugnisse in diesem Forum
Sie können in diesem Forum nicht antworten