FileZilla command line implementation of file uploads and CreateProcess implementation of silent calls

Source: Internet
Author: User
Tags filezilla

Application Requirements:

users face two scenarios when selecting a rendering job: One is to select a file on a user's remote storage, and the other is to select a file in the local file system for rendering. Because the rendering task is done on the remote host, the source file is also obtained in the FTP directory when the user chooses the file in the local file system, the file must be uploaded to the specified directory on FTP, the remote host can obtain the path to the file correctly, and then render the file after downloading. The rendering results are then saved under the specified path of FTP. Therefore, the requirement is that when the user chooses a file in the local file system, the file is automatically uploaded to the FTP directory for execution by the render program call.

Solution Analysis:

The operation of the original qftp file upload operation, but the use of qftp in the way, the upload file is not stable, and if the file is large, it is easy to error, so you want to use the external FTP tool to implement the file upload.

Here we have made it clear that the following two questions need to be addressed in order to achieve these goals: 1) filezilla the command-line form of the uploaded file. 2) How to implement FileZilla silent upload, that is, no popup window.

1) FileZilla the command-line form of the uploaded file. It took a little time to solve the problem. Google does have information about using the command line to upload files, but I'm using FileZilla.exe to check for help in Cmd, saying the command doesn't exist. After some trouble to see a post, said command support and FileZilla version, the higher version of FileZilla does not support the File Upload command line form. So, I downloaded the lower version of FileZilla, and here I'm using version 2.2.17. Use the following methods:

OK, the first problem solved, but it is not perfect, because the call is always pop-up window, although at the end of the above command add "-close", after the end of the file upload, the window will automatically close, but this will seriously affect the user experience, then focus on the problem.

2) How to implement FileZilla silent upload, that is, no popup window

At the beginning of the problem, I have been looking for its command line whether the relevant parameters can be implemented silently upload, but unfortunately, not found. Even thought of modifying the source of FileZilla, anyway it is open source. But then a thought, call it to adopt CreateProcess create a new process way, previously some impression through CreateProcess set some parameters can not display child process window. Through the access to relevant information, bingo, the scheme is feasible. The relevant code is as follows:

[CPP]View Plaincopy
  1. void Lhgoldenfarmclientprivate::startprocessdownloadfiles (const qstringlist downloadfiles)
  2. {
  3. int file_count = Downloadfiles.size ();
  4. HANDLE *file_handles = (HANDLE *) malloc (file_count*sizeof (HANDLE));
  5. For (int i = 0; i < downloadfiles.size (); i++)
  6. {
  7. Qfileinfo Files (downloadfiles.at (i));
  8. if (files.exists ()) {
  9. Startupinfo si = {sizeof (SI)};
  10. Process_information Pi;
  11. Si.dwflags = startf_useshowwindow| Startf_usestdhandles;
  12. Si.wshowwindow = Sw_hide;
  13. QString Ftphost;
  14. QString Ftpuser;
  15. QString Ftppass;
  16. Lhgoldenfarmclientprivate::mgr->getftpcredentials (Ftphost, Ftpuser, Ftppass);
  17. QString filepath = Files.absolutefilepath (). Replace ("/","\ \");
  18. QString filename = Files.filename ();
  19. QString Filesuffix = Files.suffix ();
  20. QString Destdir = QString ("Scene_files");
  21. QString s_cmdline = QString ("filezilla//filezilla.exe-r-u%1 ftp://%2:%[email protected]%4/%5-t%6-close"). Arg (FI Lepath.tolatin1 (). Data ()
  22. ). Arg (Ftpuser.tolatin1 (). data ()). Arg (Ftppass.tolatin1 (). data ()). Arg (Ftphost.tolatin1 (). data ()). Arg (
  23. Destdir.tolatin1 (). data ()). Arg (Filename.tolatin1 (). data ());
  24. Qdebug () << s_cmdline.tolatin1 (). data ();
  25. //! completion of multi-byte to wide-byte conversions
  26. WCHAR *w_cmdline = Convertfromchartowchar (S_cmdline.tolatin1 (). data ());
  27. BOOL BRet =:: CreateProcess (
  28. Null
  29. W_cmdline,
  30. Null
  31. Null
  32. FALSE,
  33. Create_no_window,
  34. Null
  35. Null
  36. &si,
  37. &pi
  38. );
  39. if (bRet) {
  40. File_handles[i] = Pi.hthread;
  41. }
  42. }
  43. }
  44. WaitForMultipleObjects (File_count, File_handles, TRUE, 3 * 60 *1000);
  45. }
This is primarily to be set at the same time: Si.wshowwindow = sw_hide and Crate_no_window parameters in CreateProcess. OK, run it, um, but the file is correctly uploaded; Run again, how can I pop up the window? The original is the file already exists, in this case, will pop-up window asks you how to operate, here to use the-r command line can set the default direct override, saying that this parameter is self-guessed, I was how great.

Summarize:

This article is mostly technical, rather than the idea of expansion. But one thing to mention here is that it took less time to solve the second problem, but it was almost beyond my expectations. And think of this method, but also inadvertently came to mind. Because used this way before, do not know why the first time did not think of this method, it seems that the knowledge is not strong enough, the lack of flexible use. But it is also in line with my current reading on their own requirements, do not try to remember something, as long as you can leave a little impression on the brain is enough, in the future when the problem, you can be impressed to know which direction to look for, perhaps this is my idea.

Cherish the time. Time is so tense, really do not want to spend a lot of time wasted on useless things, because------I am ambitious.

FileZilla command line implementation of file uploads and CreateProcess implementation of silent calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.