PDA

View Full Version : FTP_Sample_V6


SteveStation
04-25-2007, 05:23 AM
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

RizlaUK
04-25-2007, 09:41 AM
just comment out the section of code that would set "bUpload" to false


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 (http://www.indigorose.com/forums/showthread.php?t=19409)

SteveStation
04-25-2007, 11:23 AM
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.

RizlaUK
04-25-2007, 12:30 PM
yeah, as with any file explorer, just double click the file

SteveStation
04-27-2007, 05:04 PM
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.

RizlaUK
04-27-2007, 05:16 PM
try deleting the file first, then upload the new file

replace the commented out code with this

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

output enhanced with AMS Code Pretty (http://www.indigorose.com/forums/showthread.php?t=19409)

SteveStation
04-28-2007, 11:42 AM
Tanks it work perfectly

RizlaUK
04-28-2007, 12:11 PM
glad you got it working :yes