Jump to content


Photo

Help:How to change the default download folder with code?


  • Please log in to reply
3 replies to this topic

#1 qw11403

qw11403
  • Members
  • 2 posts

Posted 06 September 2007 - 07:46 AM

hi

I have created a project to do some operation with the smartFTP, and i can use the following function to download file.
enumError DownloadFile(
BSTR szRemoteFile,
BSTR szLocalFile,
long nStartPosLo,
long nStartPosHi
);
and this function have no parameter that let me to store the file to my favorite folder. the file which i downloaded is stroed in the default folder. anybody know which function i can used to change the default download fold to other place? thank you.

Brett

Edited by qw11403, 06 September 2007 - 07:48 AM.


#2 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 06 September 2007 - 11:19 AM

I do not really understand your question or problem. An example of the DownloadFile method may look like this:
DownloadFile("/Products/SmartFTP/License.txt", "C:\License.txt",0,0)

Regards,
SmartFTP

#3 qw11403

qw11403
  • Members
  • 2 posts

Posted 07 September 2007 - 08:24 AM

I do not really understand your question or problem. An example of the DownloadFile method may look like this:
DownloadFile("/Products/SmartFTP/License.txt", "C:\License.txt",0,0)

Regards,
SmartFTP



hi

Can you take some times to take a look at this issue. the objFTP.ChangeDirectory() can be used once. at the secnod time it will reply me the error ID as 15 means "FTP Library expected another server reply", can you tell me what's wrong with this?
Option Explicit On
Imports Microsoft.VisualBasic.Compatibility
Module Module1
	
	Public objFTP As sfFTPLib.FTPConnectionSTA
	Public objGlobal As sfFTPLib.Global
	Public objGeneral As sfFTPLib.FTPConnectionMTA
	
	' With events
	'Dim WithEvents objFTP As FTPConnectionSTA
	
	Public Sub Main()
		objGlobal = CreateObject("sfFTPLib.Global")
		objFTP = CreateObject("sfFTPLib.FTPConnectionSTA")

		objFTP.Host = "ServerName"
		objFTP.Port = 21
		objFTP.Protocol = sfFTPLib.enumProtocol.ftpProtocolNormal
		objFTP.Username = "UserName"
		objFTP.Password = "password"
		objFTP.Passive = True
		objFTP.LogFile = "Download Inventor.log"

		 Dim strFolder As String = "/testfolder/sqlexpress"
	   If objFTP.Connect = sfFTPLib.enumError.ftpErrorSuccess Then
			MsgBox("Connected.")
			Dim strDefaultDdFolder As String = VB6.GetPath
			DeepSearch(strFolder, "", strDefaultDdFolder)
		Else
			MsgBox("Connect() failed. LastError = " & objFTP.LastError)
		End If
	End Sub

	Public Sub DeepSearch(ByVal strOriginalFolder As String, ByVal strSubFolder As String, ByVal_ strLastDownloadFolder As String)
		Dim subItem As sfFTPLib.FTPItem
		Dim subDirectory As sfFTPLib.FTPDirectory
		Dim strNewFolder As String
		If strSubFolder = "" Then
			strNewFolder = strOriginalFolder.Trim(New Char() {"/"c})
		Else
			strNewFolder = strOriginalFolder.Trim(New Char() {"/"c}) & "/" & strSubFolder
		End If

		strNewFolder = strNewFolder.Trim(New Char() {"/"c})
		Try
			If objFTP.ChangeDirectory(strNewFolder) = sfFTPLib.enumError.ftpErrorSuccess Then
				If objFTP.ReadDirectory() = sfFTPLib.enumError.ftpErrorSuccess Then
					subDirectory = objFTP.Directory
					Dim nRestartLo As Integer = 0
					Dim nRestartHi As Integer = 0

					Dim strOriDownloadFolder As String = VB6.GetPath
					Dim strDestDownloadFolder As String = strLastDownloadFolder.Trim(New Char() {"\"c}) & "\" & strSubFolder
					strDestDownloadFolder = strDestDownloadFolder.Trim(New Char() {"\"c})
					System.IO.Directory.CreateDirectory(strDestDownloadFolder)

					For Each subItem In subDirectory
						If subItem.Type = sfFTPLib.enumItemType.ftpItemTypeFile Then
							If objFTP.DownloadFile(subItem.Name, subItem.Name, nRestartLo, nRestartHi) = sfFTPLib.enumError.ftpErrorSuccess Then
								System.IO.File.Move(strOriDownloadFolder & "\" & subItem.Name, strDestDownloadFolder & "\" & subItem.Name)
							End If
						ElseIf subItem.Type = sfFTPLib.enumItemType.ftpItemTypeFolder Then
							DeepSearch(strNewFolder, subItem.Name, strDestDownloadFolder)
						End If
					Next subItem
				End If

				objFTP.ChangeDirectory(strOriginalFolder)
				objFTP.ReadDirectory()
				subDirectory = objFTP.Directory
			Else
				MsgBox("Directory() failed. LastError = " & objFTP.LastError)
			End If
		Catch ex As Exception

		End Try
	End Sub
End Module

Edited by mb, 07 September 2007 - 05:29 PM.


#4 mb

mb

    Developer

  • Administrators
  • 11521 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 07 September 2007 - 05:32 PM

Set the LogFile property of the FTPConnection object. Then analyse the log. You are probably using a wrong directory for the ChangeDirectory command.

Regards,
Mat




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users