Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 8 of 8

Thread: FTP_Sample_V6

  1. #1
    Join Date
    Apr 2007
    Posts
    21

    FTP_Sample_V6

    http://www.indigorose.com/forums/showthread.php?t=13133
    i am using this ftp sample but i have a problem i think the solutions is simple but i dont findit. i want to the comand Dialog.FileBrowse open the file automatic to i dont nedd to press open and i dont want that the mesage apear, (File Already Exists!", "Overwrite the existing file) i want to replace the file automatic

    if FTP.IsConnected() then

    -- ask the user to browse for a file
    tbFiles = Dialog.FileBrowse(true, "Select File to Upload", "C:\\fttp\\test", "All Files (*.*)|*.*|", "test.txt", "", false, true)

    -- check for an error
    if tbFiles == nil then
    -- an error occurred
    err = Application.GetLastError();
    Dialog.Message("Error", _tblErrorMessages[err], MB_OK, MB_ICONEXCLAMATION);
    else
    -- no error...
    -- did the user cancel out of the dialog?
    if tbFiles[1] ~= "CANCEL" then
    -- they didn't cancel...we should have a file in the table
    -- we can assume it's the first item since we set MultipleSelection to false
    -- in the Dialog.FileBrowse action
    strSourceFile = tbFiles[1];

    -- split the file path into its various parts (path, filename, extension, etc.)
    tbPathParts = String.SplitPath(strSourceFile);

    -- ...now build a filename out of the parts
    strDestFile = tbPathParts.Filename..tbPathParts.Extension;

    -- flag to control whether to go through with the upload ("My Kingdom for a break command!")
    local bUpload = true;

    -- does the remote file already exist?
    if FTP.GetFileInfo(strDestFile) ~= true then

    -- destination file already exists, ask the user if it's ok to replace it
    local nResult = Dialog.Message("File Already Exists!", "Overwrite the existing file?", MB_OKCANCEL, MB_ICONQUESTION, MB_DEFBUTTON1);

    if nResult == IDCANCEL then
    -- user pressed cancel
    bUpload = false;
    end
    end

    if bUpload then

    -- show the status dialog and enable the cancel button
    StatusDlg.ShowCancelButton();
    StatusDlg.Show();

    -- upload the file
    FTP.Upload(strSourceFile, strDestFile);
    err = Application.GetLastError();

    -- hide the status dialog
    StatusDlg.Hide();

    if err == FTP.OK then
    -- update the directory list
    UpdateList();
    else
    -- FTP.Upload error!
    -- append the error message to the log
    Paragraph.SetText("Log_paragraph", Paragraph.GetText("Log_paragraph").."* Error: " .. _tblErrorMessages[err] .."\r\n");
    end
    end
    end
    end
    else
    -- not connected
    Dialog.Message("Not Connected", "You must connect to an FTP server before you can upload a file.", MB_OK, MB_ICONEXCLAMATION);
    end
    Im sory for my bad ingles

  2. #2
    Join Date
    May 2006
    Posts
    5,380
    just comment out the section of code that would set "bUpload" to false

    Code:
    if FTP.IsConnected() then 
    	-- ask the user to browse for a file
    	tbFiles = Dialog.FileBrowse(true, "Select File to Upload", "C:\\fttp\\test", "All Files (*.*)|*.*|", "test.txt", "", false, true) 
    	-- check for an error
    	if tbFiles == nil then 
    	-- an error occurred
    	err = Application.GetLastError(); 
    	Dialog.Message( "Error", _tblErrorMessages[err], MB_OK, MB_ICONEXCLAMATION); 
    	else 
    	-- no error...
    	-- did the user cancel out of the dialog?
    		if tbFiles[1] ~= "CANCEL" then 
    	 	-- they didn't cancel...we should have a file in the table
    	 	-- we can assume it's the first item since we set MultipleSelection to false
    	 	-- in the Dialog.FileBrowse action
    		strSourceFile = tbFiles[1]; 
    	 	-- split the file path into its various parts (path, filename, extension, etc.)
    		tbPathParts = String.SplitPath(strSourceFile); 
    	 	-- ...now build a filename out of the parts
    		strDestFile = tbPathParts.Filename..tbPathParts.Extension; 
    	 	-- flag to control whether to go through with the upload ("My Kingdom for a break command!")
    		local bUpload = true; 
    	 	-- does the remote file already exist?
    		 	---if FTP.GetFileInfo(strDestFile) ~= true then
    			 	-- destination file already exists, ask the user if it's ok to replace it
    			 	--local nResult = Dialog.Message("File Already Exists!", "Overwrite the existing file?", MB_OKCANCEL, MB_ICONQUESTION, MB_DEFBUTTON1);
    			 	--if nResult == IDCANCEL then
    			 	-- user pressed cancel
    			 	--bUpload = false;
    			 	--end
    		 	--end
    			
    			if bUpload then 
    		 	-- show the status dialog and enable the cancel button
    			StatusDlg.ShowCancelButton(); 
    			StatusDlg.Show(); 
    		 	-- upload the file
    			FTP.Upload(strSourceFile, strDestFile); 
    			err = Application.GetLastError(); 
    		 	-- hide the status dialog
    			StatusDlg.Hide(); 
    				if err == FTP.OK then 
    			 	-- update the directory list
    				UpdateList(); 
    				else 
    			 	-- FTP.Upload error!
    			 	-- append the error message to the log
    				Paragraph.SetText( "Log_paragraph", Paragraph.GetText( "Log_paragraph").. "* Error: " .. _tblErrorMessages[err] .. "\r\n"); 
    				end 
    			end 
    		end 
    	end 
    else 
    -- not connected
    Dialog.Message( "Not Connected", "You must connect to an FTP server before you can upload a file.", MB_OK, MB_ICONEXCLAMATION); 
    end
    output enhanced with AMS Code Pretty
    Open your eyes to Narcissism, Don't let her destroy your life!!

  3. #3
    Join Date
    Apr 2007
    Posts
    21
    Tanks that resolve my problem in (File Already Exists!", "Overwrite the existing file), but as can i open the file without having to click in the open buton, in my case say (abrir) becouse my windows is portuguese.
    Attached Images

  4. #4
    Join Date
    May 2006
    Posts
    5,380
    yeah, as with any file explorer, just double click the file
    Open your eyes to Narcissism, Don't let her destroy your life!!

  5. #5
    Join Date
    Apr 2007
    Posts
    21
    I again
    i stil need help, RizlaUK i dont want to double click in
    the file i just want to browse the file, i try to modify the line
    tbFiles = Dialog.FileBrowse(true, "Select File to Upload", "C:\\fttp\\test", "All Files (*.*)|*.*|", "test.txt", "", false, true)
    To
    tbFiles = "C:\\fttp\\test\\test.txt"
    but dont work
    and i try to use the
    FTP.Upload("C:\\fttp\\test\\test.txt
    ")
    but it wil upload the file but if the file is duplicated wil not upload.

  6. #6
    Join Date
    May 2006
    Posts
    5,380
    try deleting the file first, then upload the new file

    replace the commented out code with this
    Code:
    	 	-- does the remote file already exist?
    		 	if FTP.GetFileInfo(strDestFile) ~= true then 
    				FTP.Delete(strDestFile); 
    		 	end
    output enhanced with AMS Code Pretty
    Open your eyes to Narcissism, Don't let her destroy your life!!

  7. #7
    Join Date
    Apr 2007
    Posts
    21
    Tanks it work perfectly

  8. #8
    Join Date
    May 2006
    Posts
    5,380
    glad you got it working
    Open your eyes to Narcissism, Don't let her destroy your life!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts