简体   繁体   English

如何将所有打开的文件上传到NetBeans(PHP)中的远程主机

[英]How to upload all open files to remote host in NetBeans (PHP)

I have edited several dozens files in a wide range of directories and I first want to upload them to a test server, and then to the production server (different connections set up in NetBeans). 我已经在广泛的目录中编辑了几十个文件,我首先要将它们上传到测试服务器,然后再上传到生产服务器(在NetBeans中设置了不同的连接)。

( Edit: For server-specific reasons I can't use version control for this either. I only have FTP access. Not even SFTP. And no shell.) 编辑:出于服务器特定的原因,我也不能为此使用版本控制。我只有FTP访问权限。甚至没有SFTP。而且没有外壳。)

So, in NetBeans we can upload a single file or recursive directory easily by a keyboard shortcut or context menu. 因此,在NetBeans中,我们可以通过键盘快捷键或上下文菜单轻松上传单个文件或递归目录。

In the past I used a keyboard shortcut to upload the current file, then CTRL+W, then repeat until all files are done. 过去,我使用键盘快捷键上传当前文件,然后按CTRL + W,然后重复进行直到所有文件都完成。 But since I want to upload to two servers, this isn't an option. 但是由于我要上传到两台服务器,所以这不是一个选择。 Also, when there are many files it would be quite inconvenient any way. 同样,当文件很多时,无论如何都会带来不便。

Using NetBeans' synchronisation also does not seem to be an option, because in my source there are tens of thousands of files. 使用NetBeans同步似乎也不是一种选择,因为在我的源代码中有成千上万个文件。 An upload directory alone may also have over 10,000 files (which is the limit that FTP server is willing to serve, and I am not in a position to redesign the system to avoid having too many files in a single directory). 仅一个上传目录也可能有10,000多个文件(这是FTP服务器愿意提供的限制,并且我无法重新设计系统以避免单个目录中包含过多文件)。

I suppose I could work out all directories with edited files and attempt to synchronise them instead of the whole source, but this is also not an easy task, given several dozen files opened (I'd have to hover over each tab and see which directory it is from). 我想我可以用编辑后的文件算出所有目录,然后尝试同步它们而不是整个源,但这也不是一件容易的事,因为打开了几十个文件(我必须将鼠标悬停在每个选项卡上并查看哪个目录它来自)。 And even then NetBeans' synchronisation is quite a manual experience. 即便如此,NetBeans的同步还是相当手动的体验。

Could somebody suggest a semi-automatic (at least) method of uploading files that are open in the currently active tab? 有人可以建议一种半自动(至少)上传在当前活动选项卡中打开的文件的方法吗?

I would also like to avoid having to compare complete contents of local and remote because of the remote having gigabytes of content. 我还想避免由于本地具有千兆字节的内容而必须比较本地和远程的完整内容。

Also some files on local are different from remote and must stay that way (server-specific configs). 另外,本地的某些文件与远程的文件不同,必须保持这种方式(服务器特定的配置)。 These are obviously not amongst the currently open files. 这些显然不在当前打开的文件中。

Note: this solution is for Windows and assumes the files to be uploaded are all open files in this project. 注意:此解决方案适用于Windows,并假定要上传的文件是此项目中的所有打开文件。

So, this is not the ideal solution I was looking for, but it solved my problem. 因此,这不是我想要的理想解决方案,但是它解决了我的问题。

First, we can get the list of files that are currently open for the project by doing this (note: although this is not entirely the same as files open in a tab, but is sufficient for solving my problem, as I had a separate tab for all files related to this specific project any way): 首先,通过执行以下操作,我们可以获得当前为项目打开的文件列表(注意:尽管这与在选项卡中打开的文件并不完全相同,但是由于我有一个单独的选项卡,因此足以解决我的问题对于以任何方式与此特定项目相关的所有文件):

  1. Open the NetBeans project folder 打开NetBeans项目文件夹
  2. In the project folder, open nbproject\\private\\private.xml 在项目文件夹中,打开nbproject \\ private \\ private.xml
    It will have a list of files open for this project, eg: 它将为此项目打开一个文件列表,例如:

     <file>file:/W:/xampp/htdocs/index.php</file> <file>file:/W:/xampp/htdocs/templates/main.html</file> <file>file:/W:/xampp/htdocs/js/jquery.js</file> 
  3. Copy it to a separate text file and cut off the path up to and including remote root (htdocs) level 将其复制到单独的文本文件中,并切断到远程根目录(htdocs)的路径
    Don't forget to fix slashes eg: 不要忘记修复斜线,例如:

     index.php templates\\main.html js\\jquery.js` 

    Now that we have the list of files, we can copy them including directory structure to a temporary location, from which we will upload them to FTP 现在我们有了文件列表,我们可以将它们(包括目录结构)复制到一个临时位置,从该位置将它们上传到FTP

  4. Create a batch file prepare-patch.bat with the following contents: 创建具有以下内容的批处理文件prepare-patch.bat

     @echo off SETLOCAL EnableDelayedExpansion for /F "tokens=*" %%A in ('type %1') do ( set original_path=%~2%%A set destination_path=%~3%%A echo Copying `!original_path!` to `!destination_path!` echo f | xcopy /Y /Q "!original_path!" "!destination_path!" ) 

    It takes 3 arguments: 它需要3个参数:
    1) Path to the list of files 1)文件列表的路径
    2) Path to htdocs root 2)htdocs根目录
    3) Path to the temporary directory 3)临时目录的路径

  5. Use it like this: 像这样使用它:

     w:\\prepare-patch.bat "D:\\work\\patched_files.txt" "w:\\xampp\\htdocs\\" "w:\\temp\\" 

Now the temporary directory contains all the files with complete folder structure: 现在,临时目录包含具有完整文件夹结构的所有文件:

w:\>dir /s /b w:\temp
w:\temp\index.php
w:\temp\js
w:\temp\templates
w:\temp\js\jquery.js
w:\temp\templates\main.html

You can connect to the FTP, navigate to htdocs root and simply upload-overwrite from this temporary directory. 您可以连接到FTP,导航到htdocs根目录,然后只需从该临时目录上载-覆盖即可。

Of course, this is a lot more work than it ideally should be, but it is still faster than uploading files one by one when you have a few dozen files. 当然,这比理想情况下要完成的工作要多得多,但是仍然比有几十个文件时一个接一个地上传文件要快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM