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
- void Lhgoldenfarmclientprivate::startprocessdownloadfiles (const qstringlist downloadfiles)
- {
- int file_count = Downloadfiles.size ();
- HANDLE *file_handles = (HANDLE *) malloc (file_count*sizeof (HANDLE));
- For (int i = 0; i < downloadfiles.size (); i++)
- {
- Qfileinfo Files (downloadfiles.at (i));
- if (files.exists ()) {
- Startupinfo si = {sizeof (SI)};
- Process_information Pi;
- Si.dwflags = startf_useshowwindow| Startf_usestdhandles;
- Si.wshowwindow = Sw_hide;
- QString Ftphost;
- QString Ftpuser;
- QString Ftppass;
- Lhgoldenfarmclientprivate::mgr->getftpcredentials (Ftphost, Ftpuser, Ftppass);
- QString filepath = Files.absolutefilepath (). Replace ("/","\ \");
- QString filename = Files.filename ();
- QString Filesuffix = Files.suffix ();
- QString Destdir = QString ("Scene_files");
- QString s_cmdline = QString ("filezilla//filezilla.exe-r-u%1 ftp://%2:%[email protected]%4/%5-t%6-close"). Arg (FI Lepath.tolatin1 (). Data ()
- ). Arg (Ftpuser.tolatin1 (). data ()). Arg (Ftppass.tolatin1 (). data ()). Arg (Ftphost.tolatin1 (). data ()). Arg (
- Destdir.tolatin1 (). data ()). Arg (Filename.tolatin1 (). data ());
- Qdebug () << s_cmdline.tolatin1 (). data ();
- //! completion of multi-byte to wide-byte conversions
- WCHAR *w_cmdline = Convertfromchartowchar (S_cmdline.tolatin1 (). data ());
- BOOL BRet =:: CreateProcess (
- Null
- W_cmdline,
- Null
- Null
- FALSE,
- Create_no_window,
- Null
- Null
- &si,
- &pi
- );
- if (bRet) {
- File_handles[i] = Pi.hthread;
- }
- }
- }
- WaitForMultipleObjects (File_count, File_handles, TRUE, 3 * 60 *1000);
- }
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